作用:在访问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自定义注解--访问时验证的更多相关文章

  1. spring mvc自定义注解--登录时密码加密注解

    1,定义注解名称接口 /** * 使用该注解不用再MD5转换了 * * @author adonis * */ @Target(ElementType.PARAMETER) @Retention(Re ...

  2. Spring MVC学习总结(2)——Spring MVC常用注解说明

        使用Spring MVC的注解及其用法和其它相关知识来实现控制器功能. 02     之前在使用Struts2实现MVC的注解时,是借助struts2-convention这个插件,如今我们使 ...

  3. spring mvc 基于注解的使用总结

    本文转自http://blog.csdn.net/lufeng20/article/details/7598801 概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Sprin ...

  4. 利用Spring AOP自定义注解解决日志和签名校验

    转载:http://www.cnblogs.com/shipengzhi/articles/2716004.html 一.需解决的问题 部分API有签名参数(signature),Passport首先 ...

  5. (转)利用Spring AOP自定义注解解决日志和签名校验

    一.需解决的问题 部分API有签名参数(signature),Passport首先对签名进行校验,校验通过才会执行实现方法. 第一种实现方式(Origin):在需要签名校验的接口里写校验的代码,例如: ...

  6. Spring入门(十三):Spring MVC常用注解讲解

    在使用Spring MVC开发Web应用程序时,控制器Controller的开发非常重要,虽然说视图(JSP或者是Thymeleaf)也很重要,因为它才是直接呈现给用户的,不过由于现在前端越来越重要, ...

  7. spring AOP自定义注解方式实现日志管理

    今天继续实现AOP,到这里我个人认为是最灵活,可扩展的方式了,就拿日志管理来说,用Spring AOP 自定义注解形式实现日志管理.废话不多说,直接开始!!! 关于配置我还是的再说一遍. 在appli ...

  8. spring AOP自定义注解 实现日志管理

    今天继续实现AOP,到这里我个人认为是最灵活,可扩展的方式了,就拿日志管理来说,用Spring AOP 自定义注解形式实现日志管理.废话不多说,直接开始!!! 关于配置我还是的再说一遍. 在appli ...

  9. 当使用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 ...

随机推荐

  1. android与JS交互,互相调用方法,跳转到网页

    在main下面New - Folder - Assets Folder,在Assets下面新建一个js_android.html <html><head> <meta h ...

  2. [Usaco2007 Jan]Balanced Lineup

    嘟嘟嘟 一道RMQ板子题,分别维护最大值和最小值,不解释. #include<cstdio> #include<iostream> #include<algorithm& ...

  3. pam_frpintd.so 错误修复

    PAM unable to dlopen(/lib64/security/pam_fprintd.so): /lib64/security/pam_fprintd.so: cannot open sh ...

  4. PSR规范0-4整理

    PSR规范 psr规范 引言: PSR 是 PHP Standard Recommendations 的简写,由 PHP FIG 组织制定的 PHP 规范,是 PHP 开发的实践标准.这些规范的目的是 ...

  5. CentOS配置Hive

    hive搭建共分为三种模式:1.embedded,2.local,3.remote server 在这里,主要是配置第3种模式:remote server模式,如下图所示: 我的环境共三台虚拟机:Ho ...

  6. OO第1~3次作业总结

    作业1——多项式运算 基于度量和类图分析设计 先看Metrics插件做出的复杂度分析: 乍一看没有红色报警,其实是因为选中某一行时会自动将该行改为黑色,无论之前是红色还是蓝色emmm 真正展开第一行时 ...

  7. jquery选择器练习

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  8. Flutter - 添加从左向右滑动,返回上一个页面

    很多App比如微信.IT之家等都支持从屏幕左侧向右滑动,来返回上一个页面. 很多iOS上的App也都支持. 那么这个神奇的手势滑动是怎么实现的呢? 其实非常简单,只需要添加一句话即可. platfor ...

  9. 20155301 Exp6 信息搜集与漏洞扫描

    20155301 Exp6 信息搜集与漏洞扫描 实践内容 (1)各种搜索技巧的应用 (2)DNS IP注册信息的查询 (3)基本的扫描技术:主机发现.端口扫描.OS及服务版本探测.具体服务的查点 (4 ...

  10. linux下ipython无法保存历史记录

    在Centos7下使用ipython时,发现有个warning,提示无法保存历史记录 [root@localhost pip-]# ipython /usr/local/lib/python3./si ...