/**
* Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
*/
package com.thinkgem.jeesite.modules.sys.web; import java.util.List;
import java.util.Map; 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.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.config.Global;
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.sys.entity.Dict;
import com.thinkgem.jeesite.modules.sys.service.DictService;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils; /**
* 字典Controller
* @author ThinkGem
* @version 2014-05-16
*/
@Controller
@RequestMapping(value = "${adminPath}/sys/dict")
public class DictController extends BaseController { @Autowired
private DictService dictService; @ModelAttribute
public Dict get(@RequestParam(required=false) String id) {
if (StringUtils.isNotBlank(id)){
return dictService.get(id);
}else{
return new Dict();
}
} @RequiresPermissions("sys:dict:view")
@RequestMapping(value = {"list", ""})
public String list(Dict dict, HttpServletRequest request, HttpServletResponse response, Model model) {
List<String> typeList = dictService.findTypeList();
model.addAttribute("typeList", typeList);
Page<Dict> page = dictService.findPage(new Page<Dict>(request, response), dict);
model.addAttribute("page", page);
return "modules/sys/dictList";
} @RequiresPermissions("sys:dict:view")
@RequestMapping(value = "form")
public String form(Dict dict, Model model) {
model.addAttribute("dict", dict);
return "modules/sys/dictForm";
} @RequiresPermissions("sys:dict:edit")
@RequestMapping(value = "save")//@Valid
public String save(Dict dict, Model model, RedirectAttributes redirectAttributes) {
if(Global.isDemoMode()){
addMessage(redirectAttributes, "演示模式,不允许操作!");
return "redirect:" + adminPath + "/sys/dict/?repage&type="+dict.getType();
}
if (!beanValidator(model, dict)){
return form(dict, model);
}
dictService.save(dict);
addMessage(redirectAttributes, "保存字典'" + dict.getLabel() + "'成功");
return "redirect:" + adminPath + "/sys/dict/?repage&type="+dict.getType();
} @RequiresPermissions("sys:dict:edit")
@RequestMapping(value = "delete")
public String delete(Dict dict, RedirectAttributes redirectAttributes) {
if(Global.isDemoMode()){
addMessage(redirectAttributes, "演示模式,不允许操作!");
return "redirect:" + adminPath + "/sys/dict/?repage";
}
dictService.delete(dict);
addMessage(redirectAttributes, "删除字典成功");
return "redirect:" + adminPath + "/sys/dict/?repage&type="+dict.getType();
} @RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "treeData")
public List<Map<String, Object>> treeData(@RequestParam(required=false) String type, HttpServletResponse response) {
List<Map<String, Object>> mapList = Lists.newArrayList();
Dict dict = new Dict();
dict.setType(type);
List<Dict> list = dictService.findList(dict);
for (int i=0; i<list.size(); i++){
Dict e = list.get(i);
Map<String, Object> map = Maps.newHashMap();
map.put("id", e.getId());
map.put("pId", e.getParentId());
map.put("name", StringUtils.replace(e.getLabel(), " ", ""));
mapList.add(map);
}
return mapList;
} @ResponseBody
@RequestMapping(value = "listData")
public List<Dict> listData(@RequestParam(required=false) String type) {
Dict dict = new Dict();
dict.setType(type);
return dictService.findList(dict);
} @ResponseBody
@RequestMapping(value = "getDictLabel")
public String getDictLabel(String value, String type, String defaultValue){
if (StringUtils.isNotBlank(type) && StringUtils.isNotBlank(value)){
for (Dict dict : DictUtils.getDictList(type)){
if (type.equals(dict.getType()) && value.equals(dict.getValue())){
return dict.getLabel();
}
}
}
return defaultValue;
}
}

Controller层注解的更多相关文章

  1. spring Controller 层注解获取 properties 里面的值

    前言:最近在做一个项目,想要在 controller 层直接通过注解 @Value("")来获取 properties 里面配置的属性. 这个其实和 springmvc.sprin ...

  2. Springmvc入门基础(五) ---controller层注解及返回类型解说

    0.@Controller注解 作用:通过@Controller注解,注明该类为controller类,即控制器类,需要被spring扫描,然后注入到IOC容器中,作为Spring的Bean来管理,这 ...

  3. 通过反射获取SSM的controller层的注解以及注解中的value值

    package com.reflection.test; import java.lang.annotation.Annotation; import java.lang.reflect.Invoca ...

  4. Spring MVC 注解之controller层

    第一层注解:@Controller 和 @RestController. 这两个注解的作用是:处理页面的HTTP请求,不同点 @RestController相当于@Controller +@Respo ...

  5. spring security 在controller层 方法级别使用注解 @PreAuthorize("hasRole('ROLE_xxx')")设置权限拦截 ,无权限则返回403

    1.前言 以前学习的时候使用权限的拦截,一般都是对路径进行拦截 ,要么用拦截器设置拦截信息,要么是在配置文件内设置拦截信息, spring security 支持使用注解的形式 ,写在方法和接口上拦截 ...

  6. Junit mockito 测试Controller层方法有Pageable异常

    1.问题 在使用MockMVC+Mockito模拟Service层返回的时候,当我们在Controller层中参数方法调用有Pageable对象的时候,我们会发现,我们没办法生成一个Pageable的 ...

  7. Spring MVC中,事务是否可以加在Controller层

    一般而言,事务都是加在Service层的,但是爱钻牛角尖的我时常想:事务加在Controller层可不可以.我一直试图证明事务不止可以加在Service层,还可以加在Controller层,但是没有找 ...

  8. @ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常==》记录

    对于与数据库相关的 Spring MVC 项目,我们通常会把 事务 配置在 Service层,当数据库操作失败时让 Service 层抛出运行时异常,Spring 事物管理器就会进行回滚. 如此一来, ...

  9. 转:@ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常

    继承 ResponseEntityExceptionHandler 类来实现针对 Rest 接口 的全局异常捕获,并且可以返回自定义格式: 复制代码 1 @Slf4j 2 @ControllerAdv ...

随机推荐

  1. 中国大学MOOC 邮箱验证的问题

    在使用 中国大学 MOOC 过程中,在PC端修改个人资料时,其中有项“常用邮箱”,于是写了QQ邮箱,结果发现一直无法验证,连邮件都无法收到. 经过多番尝试,重新使用邮箱注册的方式注册账号,然后注册成功 ...

  2. SQL - 各种joins

  3. jmeter的使用---压力测试

    jmeter用于压力测试 首先我们要区别压力和攻击,当设立了不适当的线程数量和准备时长,就容易造成攻击. 线程数:虚拟用户数.一个虚拟用户占用一个进程或线程.设置多少虚拟用户数在这里也就是设置多少个线 ...

  4. Travel in desert

    传送门 不算难吧 应该有思路的 还是太水了吧 (而且和货车运输很像的啊 ---------------------------------------------------------------- ...

  5. php 加解密函数

    PHP 加密解密函数: /** * 系统加密方法 * @param string $data 要加密的字符串 * @param string $key 加密密钥 * @param int $expir ...

  6. 大组合数Lucas

    https://blog.csdn.net/sr_19930829/article/details/39058487 LL Lucas(LL n, LL m, int p){ ; } Saving B ...

  7. 多进程pipe

    pipe模块可以实现进程之间数据传递 栗子1:3个进程,一个主进程,2个子进程,三个管道,三个进程通过3个管道连接,主进程发一个信息,通过2个子进程转发,最后回到主进程输出 import multip ...

  8. java 如何快速的获取浏览量

    最近公司做了一个类似 于发帖,交友圈一个这样的功能 在如何精确快速的获取用户的浏览量,且及时的更新显示,最初我是这样想,把每条帖子内容浏览量放到reids 里面,但是redis只是用来存零时数据,想想 ...

  9. C/C++中size_t潜在的问题

    在C++中,利用数组下标访问数组元素时,常常将下标类型定义为size_t类型,因为正常来说,数组的下标就是size_t类型.例如这样: for (size_t i = 0; i < contai ...

  10. POJ 3041 Asteroids(二分图 && 匈牙利算法 && 最小点覆盖)

    嗯... 题目链接:http://poj.org/problem?id=3041 这道题的思想比较奇特: 把x坐标.y坐标分别看成是二分图两边的点,如果(x,y)上有行星,则将(x,y)之间连一条边, ...