SiteController.java
3.68 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* Copyright © 2015-2018 ODM All rights reserved.
*/
package com.thinkgem.jeesite.modules.cms.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.CookieUtils;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.cms.entity.Site;
import com.thinkgem.jeesite.modules.cms.service.SiteService;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
/**
* 站点Controller
* @author ThinkGem
* @version 2013-3-23
*/
@Controller
@RequestMapping(value = "${adminPath}/cms/site")
public class SiteController extends BaseController {
@Autowired
private SiteService siteService;
@ModelAttribute
public Site get(@RequestParam(required=false) String id) {
if (StringUtils.isNotBlank(id)){
return siteService.get(id);
}else{
return new Site();
}
}
@RequiresPermissions("cms:site:view")
@RequestMapping(value = {"list", ""})
public String list(Site site, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<Site> page = siteService.findPage(new Page<Site>(request, response), site);
model.addAttribute("page", page);
return "modules/cms/siteList";
}
@RequiresPermissions("cms:site:view")
@RequestMapping(value = "form")
public String form(Site site, Model model) {
model.addAttribute("site", site);
return "modules/cms/siteForm";
}
@RequiresPermissions("cms:site:edit")
@RequestMapping(value = "save")
public String save(Site site, Model model, RedirectAttributes redirectAttributes) {
if(Global.isDemoMode()){
addMessage(redirectAttributes, "演示模式,不允许操作!");
return "redirect:" + adminPath + "/cms/site/?repage";
}
if (!beanValidator(model, site)){
return form(site, model);
}
siteService.save(site);
addMessage(redirectAttributes, "保存站点'" + site.getName() + "'成功");
return "redirect:" + adminPath + "/cms/site/?repage";
}
@RequiresPermissions("cms:site:edit")
@RequestMapping(value = "delete")
public String delete(Site site, @RequestParam(required=false) Boolean isRe, RedirectAttributes redirectAttributes) {
if(Global.isDemoMode()){
addMessage(redirectAttributes, "演示模式,不允许操作!");
return "redirect:" + adminPath + "/cms/site/?repage";
}
if (Site.isDefault(site.getId())){
addMessage(redirectAttributes, "删除站点失败, 不允许删除默认站点");
}else{
siteService.delete(site, isRe);
addMessage(redirectAttributes, (isRe!=null&&isRe?"恢复":"")+"删除站点成功");
}
return "redirect:" + adminPath + "/cms/site/?repage";
}
/**
* 选择站点
* @param id
* @return
*/
@RequiresPermissions("cms:site:select")
@RequestMapping(value = "select")
public String select(String id, boolean flag, HttpServletResponse response){
if (id!=null){
UserUtils.putCache("siteId", id);
// 保存到Cookie中,下次登录后自动切换到该站点
CookieUtils.setCookie(response, "siteId", id);
}
if (flag){
return "redirect:" + adminPath;
}
return "modules/cms/siteSelect";
}
}