基于annotation的http请求去重插件
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/main/java/com/crossoverJie/request
.travis.yml
LICENSE
README.md
pom.xml

README.md

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