-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBusinessesController.java
More file actions
88 lines (77 loc) · 2.67 KB
/
BusinessesController.java
File metadata and controls
88 lines (77 loc) · 2.67 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
package org.imooc.controller.content;
import javax.annotation.Resource;
import org.imooc.constant.DicTypeConst;
import org.imooc.constant.PageCodeEnum;
import org.imooc.dto.BusinessDto;
import org.imooc.service.BusinessService;
import org.imooc.service.DicService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@Controller
@RequestMapping("/businesses")
public class BusinessesController {
@Resource
private DicService dicService;
@Resource
private BusinessService businessService;
/**
* 商户列表
*/
@RequestMapping(method = RequestMethod.GET)
public String search(Model model, BusinessDto dto) {
model.addAttribute("list", businessService.searchByPage(dto));
model.addAttribute("searchParam", dto);
return "/content/businessList";
}
/**
* 删除商户
*/
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public String remove(@PathVariable("id") Long id) {
return "redirect:/businesses";
}
/**
* 商户新增页初始化
*/
@RequestMapping(value = "/addPage", method = RequestMethod.GET)
public String addInit(Model model) {
model.addAttribute("cityList", dicService.getListByType(DicTypeConst.CITY));
model.addAttribute("categoryList", dicService.getListByType(DicTypeConst.CATEGORY));
return "/content/businessAdd";
}
/**
* 商户新增
*/
@RequestMapping(method = RequestMethod.POST)
public String add(BusinessDto dto,RedirectAttributes attr) {
if(businessService.add(dto)) {
attr.addAttribute(PageCodeEnum.KEY, PageCodeEnum.ADD_SUCCESS);
return "redirect:/businesses";
} else {
attr.addAttribute(PageCodeEnum.KEY, PageCodeEnum.ADD_FAIL);
return "redirect:/businesses/addPage";
}
}
/**
* 商户修改页初始化
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String modifyInit(Model model, @PathVariable("id") Long id) {
model.addAttribute("cityList", dicService.getListByType(DicTypeConst.CITY));
model.addAttribute("categoryList", dicService.getListByType(DicTypeConst.CATEGORY));
model.addAttribute("modifyObj", businessService.getById(id));
return "/content/businessModify";
}
/**
* 商户修改
*/
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public String modify(@PathVariable("id") Long id, BusinessDto dto) {
System.out.println(id);
return "/content/businessModify";
}
}