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 ...
随机推荐
- plotly线上绘图和离线绘图的区别
1.线上绘图 import plotly import plotly.plotly as py import plotly.graph_objs as go plotly.tools.set_cred ...
- Django Web接口开发
什么是接口 接口一般来讲分为两种: (1)程序内部的接口:方法与方法.模块与模块之间的交互,程序内部抛出的接口,如登录发帖,发帖就必须要登录,如果不登录不能发帖,发帖和登录这两个模块之间就要有交互,就 ...
- 深入delphi编程理解之消息(一)WINDOWS原生窗口编写及消息处理过程
通过以sdk方式编制windows窗口程序,对理解windows消息驱动机制和delphi消息编程有很大的帮助. sdk编制windows窗口程序的步骤: 1.对TWndClass对象进行赋值; 2. ...
- Java代码三级跳——表达式、语句和代码块
Java代码三级跳—表达式.语句和代码块 表达式(expression):Java中最基本的一个运算.比如一个加法运算表达式.1+2是一个表达式,a+b也是. 语句(statement):类似于平时说 ...
- 李超线段树(segment[HEOI2013]-洛谷T4097)
(neng了好久好久才糊弄懂得知识点...) 一.李超线段树 在线动态维护一个二维平面直角坐标系, 支持插入一条线段, 询问与直线x = x0相交的所有线段中,交点y的最大/小值 (若有多条线段符合条 ...
- [蓝桥杯][基础训练]2n皇后问题
Description 给定一个n*n的棋盘,棋盘中有一些位置不能放皇后.现在要向棋盘中放入n个黑皇后和n个白皇后,使任意的两个黑皇后都不在同一行.同一列或同一条对角线上,任意的两个白皇后都不在同一行 ...
- 吴裕雄--天生自然神经网络与深度学习实战Python+Keras+TensorFlow:RNN和CNN混合的鸡尾酒疗法提升网络运行效率
from keras.layers import model = Sequential() model.add(embedding_layer) #使用一维卷积网络切割输入数据,参数5表示每各个单词作 ...
- js正则验证表达式验证
/* 合法uri */ export function validateURL(textval) { const urlregex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\ ...
- HDU 1312 Red and Black(经典DFS)
嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 一道很经典的dfs,设置上下左右四个方向,读入时记下起点,然后跑dfs即可...最后答 ...
- Vue-全局变量和方法
一.单文件引入 1.创建存放全局变量和方法的vue文件 Common.uve <script> const userName = 'yangjing'; function add(a,b) ...