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 ...
随机推荐
- 一文搞懂vim复制粘贴
转载自本人独立博客https://liushiming.cn/2020/01/18/copy-and-paste-in-vim/ 概述 复制粘贴是文本编辑最常用的功能,但是在vim中复制粘贴还是有点麻 ...
- docker删除mysql镜像失败Error response from daemon: conflict: unable to delete 8809d5286227 (must be forced) - image is being used by stopped container 1a2a427273b3
错误解析:这是由于要删除的目标镜像中有容器存在,故无法删除镜像 解决办法:先删除镜像中的容器,再删除该镜像.
- C语言笔记 10_文件读写&预处理器
文件读写 上一章我们讲解了 C 语言处理的标准输入和输出设备.本章我们将介绍 C 程序员如何创建.打开.关闭文本文件或二进制文件. 一个文件,无论它是文本文件还是二进制文件,都是代表了一系列的字节.C ...
- opencv:自定义滤波
卷积核的定义 均值卷积核 // 自定义滤波 - 均值卷积 int k = 15; Mat mkernel = Mat::ones(k, k, CV_32F) / (float)(k * k); Mat ...
- 安装Linux系统后配置的一般步骤
安装linux后配置的一般步骤 最近在尝试不同的linux系统,记录一下安装完linux之后常用的软件的安装方法 1.源的更新 ubuntu 源的更新方法 参考(没有测试过,但是都大同小异,不行就换一 ...
- Floyd-Warshall
Description 第一行四个数为n,m,n表示顶点个数,m表示边的条数. 接下来m行,每一行有三个数t1.t2 和t3,表示顶点t1到顶点t2的路程是t3.请注意这些t1->t2是单向的. ...
- Spring扫描组件的使用详解
https://blog.csdn.net/you18131371836/article/details/53691044?utm_source=blogxgwz5
- VisualTreeHelper 向下提取 元素
private ChildType FindVisualChild<ChildType>(DependencyObject obj) where ChildType : Dependenc ...
- JavaScript - 代码片段,Snippets,Gist
求n个数字的累加和 递归实现 function getSum(x) { if (x == 1) { return 1; } return x + getSum(x - 1); } var result ...
- 【代码学习】PYTHON 异常处理
一.什么是异常 在程序执行过程中可能会影响程序的正常执行,一般情况下,在python无法正常处理程序时就会发生一个异常 当python脚本发生异常时我们需要捕获处理他,否则程序会终止执行 二.异常处理 ...