介绍
这篇文章将为大家详细讲解有关怎么在春天引导中防止重复提交,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
砰的一声。xml
& lt; ? xml version=?.0“,编码=癠TF-8" ?比; & lt; project  xmlns=癶ttp://maven.apache.org/POM/4.0.0", xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance" ,,xsi: schemaLocation=? http://maven.apache.org/POM/4.0.0 , http://maven.apache.org/xsd/maven-4.0.0.xsd"比; ,& lt; modelVersion> 4.0.0 ,& lt; groupId> com.example ,& lt; artifactId> springboot-repeat-submit ,& lt; version> 1.0 & lt;/version> ,& lt; packaging> jar ,& lt; parent> & lt;才能groupId> org.springframework.boot</groupId> & lt;才能artifactId> spring-boot-starter-parent</artifactId> & lt;才能version> 2.0.4.RELEASE</version> & lt;才能relativePath/祝辞,& lt; !——, lookup parent 得到repository ——比; ,& lt;/parent> ,& lt; properties> & lt;才能project.build.sourceEncoding> UTF-8</project.build.sourceEncoding> & lt;才能project.reporting.outputEncoding> UTF-8</project.reporting.outputEncoding> & lt;才能java.version> 1.8 & lt;/java.version> ,& lt;/properties> ,& lt; dependencies> & lt;才能dependency> ,,& lt; groupId> org.springframework.boot ,,& lt; artifactId> spring-boot-starter-web & lt;才能/dependency> & lt;才能dependency> ,,& lt; groupId> org.springframework.boot ,,& lt; artifactId> spring-boot-starter-aop & lt;才能/dependency> & lt;才能dependency> ,,& lt; groupId> com.google.guava ,,& lt; artifactId> guava ,,& lt; version> 24.0 -jre & lt;才能/dependency> ,& lt;/dependencies> ,& lt; build> & lt;才能plugins> ,,& lt; plugin> ,,,& lt; groupId> org.springframework.boot ,,,& lt; artifactId> spring-boot-maven-plugin ,,& lt;/plugin> & lt;才能/plugins> ,& lt;/build> & lt;/project>
<强>应用程序。java 强>
package com; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;/* * ,* @author www.gaozz.club ,* @功能描述,防重复提交 ,* @date 2018-08-26 ,*/@SpringBootApplication public class  Application { ,public static  void main (String [], args), { SpringApplication.run才能(Application.class, args); ,} }
<>强自定义注解NoRepeatSubmit。java 强>
package com.common; 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),//,运行时有效/* * ,* @功能描述,防止重复提交标记注解 ,* @author www.gaozz.club ,* @date 2018-08-26 ,*/public @interface  NoRepeatSubmit { }
<>强aop解析注解NoRepeatSubmitAop。java 强>
package com.common; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import com.google.common.cache.Cache; @Aspect @ component/* * ,* @功能描述,aop解析注解 ,* @author www.gaozz.club ,* @date 2018-08-26 ,*/public class  NoRepeatSubmitAop { ,private Log logger =, LogFactory.getLog (getClass ()); ,@ autowired ,private Cache<字符串,Integer>,缓存; ,@Around(“执行(com . example . . *, *控制器。* (. .)),,,,@annotation (nrs)“) 周围的,public Object (ProceedingJoinPoint pjp, NoRepeatSubmit 关系),{ try {才能 ,,ServletRequestAttributes attributes =, (ServletRequestAttributes), RequestContextHolder.getRequestAttributes (); null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null怎么在春天引导中防止重复提交