<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.bitspace.bourse.core.interceptor.NoRepeatInterceptor"></bean>
</mvc:interceptor>
import com.alibaba.fastjson.JSON;
import com.bitspace.bourse.core.annotation.NoRepeatData;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map; public class NoRepeatInterceptor extends HandlerInterceptorAdapter { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();
NoRepeatData annotation = method.getAnnotation(NoRepeatData.class);
if (annotation != null) {
if (repeatDataValidator(request)) {//如果重复相同数据
return false;
} else {
return true;
}
}
return true;
} else {
return super.preHandle(request, response, handler);
}
} public boolean repeatDataValidator(HttpServletRequest httpServletRequest) {
String params = JSON.toJSONString(httpServletRequest.getParameterMap());
String url = httpServletRequest.getRequestURI();
Map<String, String> map = new HashMap<String, String>();
map.put(url, params);
String nowUrlParams = map.toString(); Object preUrlParams = httpServletRequest.getSession().getAttribute("repeatData");
if (preUrlParams == null) {//如果上一个数据为null,表示还没有访问页面
httpServletRequest.getSession().setAttribute("repeatData", nowUrlParams);
return false;
} else {//否则,已经访问过页面
if (preUrlParams.toString().equals(nowUrlParams)) {//如果上次url+数据和本次url+数据相同,则表示城府添加数据
return true;
} else {//如果上次 url+数据 和本次url加数据不同,则不是重复提交
httpServletRequest.getSession().setAttribute("repeatData", nowUrlParams);
return false;
} } } }
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface NoRepeatData {
}

springMVC 防重校验(拦截器)的更多相关文章

  1. SpringMVC中的Interceptor拦截器及与Filter区别

    SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.比如通过它来进行权限验证,或者是来判断用户是否登陆,或者是像12306 那 ...

  2. springMVC学习(12)-使用拦截器

    一.拦截器配置和测试: 1)定义两个拦截器,(要实现HandlerInterceptor接口) HandlerInterceptor1: package com.cy.interceptor; imp ...

  3. SpringMVC中使用Interceptor拦截器

    SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.比如通过它来进行权限验证,或者是来判断用户是否登陆,或者是像12306 那 ...

  4. SpringMVC 中的Interceptor 拦截器

    1.配置拦截器 在springMVC.xml配置文件增加: <mvc:interceptors>  <!-- 日志拦截器 -->  <mvc:interceptor> ...

  5. SpringMVC中使用Interceptor拦截器顺序

    一.简介 SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.比如通过它来进行权限验 证,或者是来判断用户是否登陆,或者是像1 ...

  6. java框架之SpringMVC(2)-补充及拦截器

    高级参数绑定 package com.zze.springmvc.web.controller; import org.springframework.stereotype.Controller; i ...

  7. springMVC之mvc:interceptors拦截器的用法

    1.配置拦截器 在springMVC.xml配置文件增加: <mvc:interceptors> <!-- 日志拦截器 --> <mvc:interceptor> ...

  8. [转]SpringMVC中使用Interceptor拦截器

    SpringMVC 中的Interceptor 拦截器也是相当重要和相当有用的,它的主要作用是拦截用户的请求并进行相应的处理.比如通过它来进行权限验证,或者是来判断用户是否登陆,或者是像12306 那 ...

  9. JAVAEE——SSH项目实战05:用户注册、登陆校验拦截器、员工拜访客户功能和MD5加密

    作者: kent鹏 转载请注明出处: http://www.cnblogs.com/xieyupeng/p/7170519.html 一.用户注册   显示错误信息到页面上的另一种方法: public ...

随机推荐

  1. 玩转ptrace(转)

    下面是转帖的内容,写的很详细.但是不同的linux发行版中头文件的路径和名称并不相同.如在某些发行版中<linux/user.h>就不存在,其中定义的变量出现在<asm/ptrace ...

  2. SWD and JTAG selection mechanism

    SWD and JTAG selection mechanism SWJ-DP enables either an SWD or JTAG protocol to be used on the deb ...

  3. STM32的PWM输入模式设置并用DMA接收数据

    参考 :STM32输入捕获模式设置并用DMA接收数据 PWM input mode This mode is a particular case of input capture mode. The ...

  4. Understanding the STM32F0's GPIO

    Understanding the STM32F0's GPIO This is the first part of the GPIO tutorial for the STM32F0Discover ...

  5. 执行nova-manage db sync时出错,提示’Specified key was too long; max key length is 1000 bytes’

    执行nova-manage db sync时出错: 2012-03-24 14:07:01 CRITICAL nova [-] (OperationalError) (1071, ‘Specified ...

  6. tomcat内存溢出设置JAVA_OPTS

     答案1设置Tomcat启动的初始内存其初始空间(即-Xms)是物理内存的1/64,最大空间(-Xmx)是物理内存的1/4.可以利用JVM提供的-Xmn -Xms -Xmx等选项可进行设置三.实例,以 ...

  7. iOS 32位、 64位系统兼容性设置-Xcode创建支持IOS4.3以上版本的应用的方法

    方法一: 如果是Xcode 5的话步骤为 点击项目名称->Build Settings->搜索 Architectures 这个里面的原始的值是Standard architectures ...

  8. 查询死锁的Session SQL 语句

    /* Formatted on 2018/3/14 23:34:49 (QP5 v5.256.13226.35538) */ SELECT dob.object_name table_name , l ...

  9. cocos2d-x retain和release倒底怎么玩?

    转载请注明,原文地址: http://blog.csdn.net/musicvs/article/details/8689345 正文: 1. 为什么会有retain? C++和Java不一样,Jav ...

  10. sql语句 update 字段=字段+字符串

    update aa set name=concat('x',name) SELECT OWNER,phone ,COUNT(fc_hc) as c from tb_p GROUP BY fc_hc H ...