-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdController.java
More file actions
98 lines (87 loc) · 2.51 KB
/
AdController.java
File metadata and controls
98 lines (87 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package org.imooc.controller.content;
import javax.servlet.http.HttpServletRequest;
import org.imooc.constant.PageCodeEnum;
import org.imooc.dto.AdDto;
import org.imooc.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping("/ad")
public class AdController {
@Autowired
private AdService adService;
/**
* 广告管理页初始化(点广告管理菜单进入的第一个页面)
*/
@RequestMapping
public String init(Model model, HttpServletRequest request) {
AdDto adDto = new AdDto();
model.addAttribute("list", adService.searchByPage(adDto));
model.addAttribute("searchParam", adDto);
return "/content/adList";
}
/**
* 查询
*/
@RequestMapping("/search")
public String search(Model model, AdDto adDto) {
model.addAttribute("list", adService.searchByPage(adDto));
model.addAttribute("searchParam", adDto);
return "/content/adList";
}
/**
* 删除
*/
@RequestMapping("/remove")
public String remove(@RequestParam("id") Long id,Model model) {
if(adService.remove(id)) {
model.addAttribute(PageCodeEnum.KEY, PageCodeEnum.REMOVE_SUCCESS);
} else {
model.addAttribute(PageCodeEnum.KEY, PageCodeEnum.REMOVE_FAIL);
}
return "forward:/ad";
}
/**
* 新增页初始化
*/
@RequestMapping("/addInit")
public String addInit() {
return "/content/adAdd";
}
/**
* 新增
*/
@RequestMapping("/add")
public String add(AdDto adDto, Model model) {
if (adService.add(adDto)) {
model.addAttribute(PageCodeEnum.KEY, PageCodeEnum.ADD_SUCCESS);
} else {
model.addAttribute(PageCodeEnum.KEY, PageCodeEnum.ADD_FAIL);
}
return "/content/adAdd";
}
/**
* 修改页初始化
*/
@RequestMapping("/modifyInit")
public String modifyInit(Model model, @RequestParam("id") Long id) {
model.addAttribute("modifyObj", adService.getById(id));
return "/content/adModify";
}
/**
* 修改
*/
@RequestMapping("/modify")
public String modify(Model model, AdDto adDto) {
model.addAttribute("modifyObj", adDto);
if (adService.modify(adDto)) {
model.addAttribute(PageCodeEnum.KEY, PageCodeEnum.MODIFY_SUCCESS);
} else {
model.addAttribute(PageCodeEnum.KEY, PageCodeEnum.MODIFY_FAIL);
}
return "/content/adModify";
}
}