LinkController.java
4.21 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
113
114
115
116
117
118
119
120
121
/**
* Copyright © 2015-2018 ODM All rights reserved.
*/
package com.thinkgem.jeesite.modules.cms.web;
import java.util.List;
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.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.thinkgem.jeesite.common.mapper.JsonMapper;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.cms.entity.Category;
import com.thinkgem.jeesite.modules.cms.entity.Link;
import com.thinkgem.jeesite.modules.cms.entity.Site;
import com.thinkgem.jeesite.modules.cms.service.CategoryService;
import com.thinkgem.jeesite.modules.cms.service.LinkService;
/**
* 链接Controller
* @author ThinkGem
* @version 2013-3-23
*/
@Controller
@RequestMapping(value = "${adminPath}/cms/link")
public class LinkController extends BaseController {
@Autowired
private LinkService linkService;
@Autowired
private CategoryService categoryService;
@ModelAttribute
public Link get(@RequestParam(required=false) String id) {
if (StringUtils.isNotBlank(id)){
return linkService.get(id);
}else{
return new Link();
}
}
@RequiresPermissions("cms:link:view")
@RequestMapping(value = {"list", ""})
public String list(Link link, HttpServletRequest request, HttpServletResponse response, Model model) {
// User user = UserUtils.getUser();
// if (!user.isAdmin() && !SecurityUtils.getSubject().isPermitted("cms:link:audit")){
// link.setUser(user);
// }
Page<Link> page = linkService.findPage(new Page<Link>(request, response), link, true);
model.addAttribute("page", page);
return "modules/cms/linkList";
}
@RequiresPermissions("cms:link:view")
@RequestMapping(value = "form")
public String form(Link link, Model model) {
// 如果当前传参有子节点,则选择取消传参选择
if (link.getCategory()!=null && StringUtils.isNotBlank(link.getCategory().getId())){
List<Category> list = categoryService.findByParentId(link.getCategory().getId(), Site.getCurrentSiteId());
if (list.size() > 0){
link.setCategory(null);
}else{
link.setCategory(categoryService.get(link.getCategory().getId()));
}
}
model.addAttribute("link", link);
return "modules/cms/linkForm";
}
@RequiresPermissions("cms:link:edit")
@RequestMapping(value = "save")
public String save(Link link, Model model, RedirectAttributes redirectAttributes) {
if (!beanValidator(model, link)){
return form(link, model);
}
linkService.save(link);
addMessage(redirectAttributes, "保存链接'" + StringUtils.abbr(link.getTitle(),50) + "'成功");
return "redirect:" + adminPath + "/cms/link/?repage&category.id="+link.getCategory().getId();
}
@RequiresPermissions("cms:link:edit")
@RequestMapping(value = "delete")
public String delete(Link link, String categoryId, @RequestParam(required=false) Boolean isRe, RedirectAttributes redirectAttributes) {
linkService.delete(link, isRe);
addMessage(redirectAttributes, (isRe!=null&&isRe?"发布":"删除")+"链接成功");
return "redirect:" + adminPath + "/cms/link/?repage&category.id="+categoryId;
}
/**
* 链接选择列表
*/
@RequiresPermissions("cms:link:view")
@RequestMapping(value = "selectList")
public String selectList(Link link, HttpServletRequest request, HttpServletResponse response, Model model) {
list(link, request, response, model);
return "modules/cms/linkSelectList";
}
/**
* 通过编号获取链接名称
*/
@RequiresPermissions("cms:link:view")
@ResponseBody
@RequestMapping(value = "findByIds")
public String findByIds(String ids) {
List<Object[]> list = linkService.findByIds(ids);
return JsonMapper.nonDefaultMapper().toJson(list);
}
}