目录
回顾上一章:
在上一章中,我们有介绍到一种避免表单重复提交的解决方案。但这种解决方案有这2个缺点
其一:如果我们要想让这个表单可以避免重复提交,那么需要往表单当中添加隐藏域,如此要是有很多地方的表单都需要避免重复提交的功能,那么在每个表单当中都必须添加这隐藏域!
其二:之前介绍的那种方式不够灵活。比如说 要实现10秒内点击的刷新属于重复提交,超过10秒点击刷新不属于重复提交 。用这种方式很难实现
本章要实现的功能:
1、通过 拦截器来实现避免表单重复提交的功能(10秒内刷新属于重复提交, 超过10秒刷新不属于重复提交)
2、自定义注解,不是所有的Controller都需要避免重复提交的功能的,只有访问的是 标有 自定义的注解的方法才需要考虑
一、login.jsp 页面
二、 自定义注解防止表单重复提交
package com.lcy.annotation;
import java.lang.annotation.*;
/**
* 自定义注解防止表单重复提交
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RepeatSubmit {
}
三、防止重复提交拦截器
RepeatSubmitInterceptor 类
package com.lcy.interceptor;
import com.lcy.annotation.RepeatSubmit;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapt