Controller层注解
/**
* Copyright © 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层注解的更多相关文章
- spring Controller 层注解获取 properties 里面的值
前言:最近在做一个项目,想要在 controller 层直接通过注解 @Value("")来获取 properties 里面配置的属性. 这个其实和 springmvc.sprin ...
- Springmvc入门基础(五) ---controller层注解及返回类型解说
0.@Controller注解 作用:通过@Controller注解,注明该类为controller类,即控制器类,需要被spring扫描,然后注入到IOC容器中,作为Spring的Bean来管理,这 ...
- 通过反射获取SSM的controller层的注解以及注解中的value值
package com.reflection.test; import java.lang.annotation.Annotation; import java.lang.reflect.Invoca ...
- Spring MVC 注解之controller层
第一层注解:@Controller 和 @RestController. 这两个注解的作用是:处理页面的HTTP请求,不同点 @RestController相当于@Controller +@Respo ...
- spring security 在controller层 方法级别使用注解 @PreAuthorize("hasRole('ROLE_xxx')")设置权限拦截 ,无权限则返回403
1.前言 以前学习的时候使用权限的拦截,一般都是对路径进行拦截 ,要么用拦截器设置拦截信息,要么是在配置文件内设置拦截信息, spring security 支持使用注解的形式 ,写在方法和接口上拦截 ...
- Junit mockito 测试Controller层方法有Pageable异常
1.问题 在使用MockMVC+Mockito模拟Service层返回的时候,当我们在Controller层中参数方法调用有Pageable对象的时候,我们会发现,我们没办法生成一个Pageable的 ...
- Spring MVC中,事务是否可以加在Controller层
一般而言,事务都是加在Service层的,但是爱钻牛角尖的我时常想:事务加在Controller层可不可以.我一直试图证明事务不止可以加在Service层,还可以加在Controller层,但是没有找 ...
- @ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常==》记录
对于与数据库相关的 Spring MVC 项目,我们通常会把 事务 配置在 Service层,当数据库操作失败时让 Service 层抛出运行时异常,Spring 事物管理器就会进行回滚. 如此一来, ...
- 转:@ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常
继承 ResponseEntityExceptionHandler 类来实现针对 Rest 接口 的全局异常捕获,并且可以返回自定义格式: 复制代码 1 @Slf4j 2 @ControllerAdv ...
随机推荐
- MongoDB - 将查询结果保存到excel文件中
import pymongo import re client = pymongo.MongoClient('127.0.0.1', 27017) db_name = 'Trade' db = cli ...
- 原生js登录创建cookie
原生js创建cookie,功能:点击登录按钮时,将用户名.密码存为cookie:页面再次加载时,自动读取cookie中的用户名.密码. <html><head><titl ...
- Python(五) 迭代器(Iterable/Iterator/iter())
原文的链接:http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143178254 ...
- 支付接口API
//微信支付SDK https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1
- Zabbix监控工具介绍及软件监控、硬件监控及报警练习
zabbix介绍 zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供 ...
- C语言:将字符串中的字符逆序输出,但不改变字符串中的内容。-在main函数中将多次调用fun函数,每调用一次,输出链表尾部结点中的数据,并释放该结点,使链表缩短。
//将字符串中的字符逆序输出,但不改变字符串中的内容. #include <stdio.h> /************found************/ void fun (char ...
- Vue-阻止页面回退
1.原生js方法 <script language="javascript"> //防止页面后退 使用在vue时 挂载到mounted中 history.pushSta ...
- KK音标
目录 KK音标 参考 音标发音 音标口诀 五个规则 KK音标
- 探索 Python + HyperLPR 进行车牌识别
概要 HyperLRP是一个开源的.基于深度学习高性能中文车牌识别库,由北京智云视图科技有限公司开发,支持PHP.C/C++.Python语言,Windows/Mac/Linux/Android/IO ...
- JavaSE复习~基本数据类型
数据类型 java有两大类数据类型:基本数据类型 和 引用数据类型 基本数据类型 整数型:byte.short.int.long 浮点型:float.double 字符型:char 布尔型:boole ...