注解的用法
来源:互联网 发布:安知玉如意好看吗 编辑:程序博客网 时间:2024/05/20 03:48
1.用于切面编程
@Target({ElementType.PARAMETER, ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface SystemServiceLog { String description() default "";}
@Pointcut("@annotation(com.gidoor.zcwd.web.annotation.SystemServiceLog)")public void serviceAspect() {}
@AfterThrowing(pointcut = "serviceAspect()", throwing = "e")public void doAfterThrowing(JoinPoint joinPoint, Throwable e) { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();}2.用于拦截
/** * 权限限制 * @author 2015-12-12 18:29:02 */@Target(ElementType.METHOD)@Retention(RetentionPolicy.RUNTIME)public @interface PermessionLimit { /** * 登录拦截 (默认拦截) */ boolean limit() default true;}
/** * 权限拦截, 简易版 * @author 2015-12-12 18:09:04 */public class PermissionInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (!(handler instanceof HandlerMethod)) { return super.preHandle(request, response, handler); } if (!ifLogin(request)) { HandlerMethod method = (HandlerMethod)handler; PermessionLimit permission = method.getMethodAnnotation(PermessionLimit.class); if (permission == null || permission.limit()) { response.sendRedirect(request.getContextPath() + "/toLogin"); //request.getRequestDispatcher("/toLogin").forward(request, response); return false; } } return super.preHandle(request, response, handler); } }
@RequestMapping("/toLogin")@PermessionLimit(limit=false)public String toLogin(Model model, HttpServletRequest request) { if (PermissionInterceptor.ifLogin(request)) { return "redirect:/"; } return "login";
阅读全文
0 0
- @SuppressWarnings注解的用法
- @ModelAttribute注解的用法
- @XStreamAlias注解的用法。
- java注解的用法
- @RequestMapping注解的用法
- @RequestMapping注解的用法
- 注解的用法
- 注解的用法
- @RequestMapping注解的用法
- @RequestMapping注解的用法
- @RequestMapping注解的用法
- @RequestBody注解的用法
- Python中@注解的用法
- jpa注解的一些用法
- Spring注解的基础用法
- springMVC注解@ModelAttribute的用法
- Java注解@interface的用法
- @Param注解的用法解析
- 1.swoole 简介
- [1] 开通博客
- Ubuntu环境QT出现:-1: error: cannot find -lGL(已解决)
- 【数据结构】哈夫曼树及哈夫曼编码译码
- 10.ipcs
- 注解的用法
- 2017-06-21 星期三
- vue.js 底部导航栏 一级路由显示 子路由不显示
- robotframework的mac版本安装
- Layui自定义模块基础学习
- Docker Swarm 和Swarm mode 是两个概念!!
- nagios安装使用指南
- 设计模式->行为型模式->迭代器模式
- 最长公共子序列LCS-DP