Skip to content

crossoverJie/SSM-REQUEST-CHECK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

开发

https://crossoverjie.top/2017/05/24/SSM14/

预览

重复请求号01.jpg 重复请求号02.jpg 重复请求号03.jpg

简介

基于annotation的http去重插件:

  • Redis保存请求。
  • Spring AOP 进行切面。

后续会用Spring Boot重构

安装

https://github.com/crossoverJie/SSM-REQUEST-CHECK.git
cd SSM-REQUEST-CHECK
mvn clean
mvn install

使用

加入依赖

<dependency>
    <groupId>com.crossoverJie</groupId>
    <artifactId>SSM-REQUEST-CHECK</artifactId>
    <version>1.0.0</version>
</dependency>

开启CGLIB代理

需要根据自己web.xml中定义的

    <!-- Spring MVC servlet -->
    <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>

spring-mvc.xml文件中配置:

<aop:aspectj-autoproxy proxy-target-class="true"></aop:aspectj-autoproxy>

使用注解

    @CheckReqNo
    @RequestMapping(value = "/createRedisContent",method = RequestMethod.POST)
    @ResponseBody
    public BaseResponse<NULLBody> createRedisContent(@RequestBody RedisContentReq redisContentReq){
        BaseResponse<NULLBody> response = new BaseResponse<NULLBody>() ;

        Rediscontent rediscontent = new Rediscontent() ;
        try {
            CommonUtil.setLogValueModelToModel(redisContentReq,rediscontent);
            rediscontentMapper.insertSelective(rediscontent) ;
            response.setReqNo(redisContentReq.getReqNo());
            response.setCode(StatusEnum.SUCCESS.getCode());
            response.setMessage(StatusEnum.SUCCESS.getMessage());
        }catch (Exception e){
            logger.error("system error",e);
            response.setReqNo(response.getReqNo());
            response.setCode(StatusEnum.FAIL.getCode());
            response.setMessage(StatusEnum.FAIL.getMessage());
        }

        return response ;

    }

自定义缓存前缀、时间

默认缓存前缀是reqNo,时间为1天。

#redis前缀
redis.prefixReq=reqNo
#redis缓存时间 默认单位为天
redis.day=1

联系作者

weixinchat.jpg