spring mvc自定义注解--访问时验证
作用:在访问controller的方法时,判断用户是否是登陆状态。
step1:定义注解
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; @Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface LoginRequired { public String loginUrl() default ""; }
step2:定义拦截器,继承HandlerInterceptorAdapter抽象类,重新preHandle方法
public class TicketInterceptor extends HandlerInterceptorAdapter {
@Autowired
private UserDetailMapper userDetailMapper;
@Autowired
private UserRoleService userRoleService;
@Autowired
private UserOrgMapper userOrgMapper;// add by cuiyan 20150604 用户机构
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
LoginRequired loginRequired = MethodInterceptorUtils.getAnnotaion(
handler, LoginRequired.class);
//..........判断逻辑
}
}
step3:springmvc的配置文件,拦截器
<mvc:interceptors>
<bean class="xxxx" />
</mvc:interceptors>
spring mvc自定义注解--访问时验证的更多相关文章
- spring mvc自定义注解--登录时密码加密注解
1,定义注解名称接口 /** * 使用该注解不用再MD5转换了 * * @author adonis * */ @Target(ElementType.PARAMETER) @Retention(Re ...
- Spring MVC学习总结(2)——Spring MVC常用注解说明
使用Spring MVC的注解及其用法和其它相关知识来实现控制器功能. 02 之前在使用Struts2实现MVC的注解时,是借助struts2-convention这个插件,如今我们使 ...
- spring mvc 基于注解的使用总结
本文转自http://blog.csdn.net/lufeng20/article/details/7598801 概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Sprin ...
- 利用Spring AOP自定义注解解决日志和签名校验
转载:http://www.cnblogs.com/shipengzhi/articles/2716004.html 一.需解决的问题 部分API有签名参数(signature),Passport首先 ...
- (转)利用Spring AOP自定义注解解决日志和签名校验
一.需解决的问题 部分API有签名参数(signature),Passport首先对签名进行校验,校验通过才会执行实现方法. 第一种实现方式(Origin):在需要签名校验的接口里写校验的代码,例如: ...
- Spring入门(十三):Spring MVC常用注解讲解
在使用Spring MVC开发Web应用程序时,控制器Controller的开发非常重要,虽然说视图(JSP或者是Thymeleaf)也很重要,因为它才是直接呈现给用户的,不过由于现在前端越来越重要, ...
- spring AOP自定义注解方式实现日志管理
今天继续实现AOP,到这里我个人认为是最灵活,可扩展的方式了,就拿日志管理来说,用Spring AOP 自定义注解形式实现日志管理.废话不多说,直接开始!!! 关于配置我还是的再说一遍. 在appli ...
- spring AOP自定义注解 实现日志管理
今天继续实现AOP,到这里我个人认为是最灵活,可扩展的方式了,就拿日志管理来说,用Spring AOP 自定义注解形式实现日志管理.废话不多说,直接开始!!! 关于配置我还是的再说一遍. 在appli ...
- 当使用Spring MVC @Valid对输入框进行验证的时候,可能会遇到以下的异常:Neither BindingResult nor plain target object for bean name ‘mybean’ available as request attribute
转自:https://www.cnblogs.com/wenhulu/p/5555457.html 当使用Spring MVC @Valid对输入框进行验证的时候,可能会遇到以下的异常: Neithe ...
随机推荐
- css 文本溢出
多行文本溢出处理: display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; // 3 行 overflow ...
- scrt中使用alt键
session Options-->Terminal---->Emulation------>Emacs----->Use ALT as meta key
- 【转】系统去掉 Android 4.4.2 的StatusBar和NavigationBar
系统Hide Status Bar frameworks/base/core/res/res/values/dimens.xml 把 <dimen name="status_bar_ ...
- $Simpson$积分入门
\(\rm{0x01}\) 前言 首先阐明一点,自适应辛普森算法(\(\rm{Adaptive ~Simpson's~ rule}\) )是一类近似算法(\(\rm{Approximation ~al ...
- 例子:照片的OCR识别
来自ng的ml-003中 18_XVIII._Application_Example-_Photo_OCR 这是ng2013年在coursera上最后的一课了.这一系列的几个视频还是相比前面有些难懂, ...
- OC实现个人中心页面
AppDelegate.m: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDic ...
- Net Core 使用外部登陆提供程序登陆的流程,以及身份认证的流程
在Asp.Net Core 中使用外部登陆(google.微博...) 原文出自Rui Figueiredo的博文<External Login Providers in ASP.NET C ...
- Python3入门(十)——调试与测试
一.异常处理 1.try...except...finally... 这个也就是Java里的try...cath..finally...了,直接看经典代码: try: print("开始执行 ...
- 20155325 Exp9 Web安全基础
本实践的目标理解常用网络攻击技术的基本原理.Webgoat实践下相关实验. 实验后回答问题 (1)SQL注入攻击原理,如何防御 原理:SQL注入即是指web应用程序对用户输入数据的合法性没有判断,攻击 ...
- FAT32文件系统学习(1) —— BPB的理解
FAT 32 文件系统学习 1.本文的目标 本文将通过实际读取一个FAT32格式的U盘来简单了解和学习FAT32文件系统的格式.虽然目前windwos操作系统的主流文件系统格式是NTFS,但是FAT3 ...