当前位置: 首页 > news >正文

服装设计师参考的网站手机百度app下载

服装设计师参考的网站,手机百度app下载,北京和田合瑞建设有限公司网站,表白网页设计代码大全若依框架实现后端防止用户重复点击 基于自定义注解、切面、Redis实现 1. 添加自定义注解: 代码放置位置:com/ruoyi/common/annotation/RepeatClick.java time: 时间默认0; unit:单位默认 秒; key: 默认空字符串 package com.ruoyi.fra…

若依框架实现后端防止用户重复点击

基于自定义注解、切面、Redis实现

1. 添加自定义注解:

代码放置位置:com/ruoyi/common/annotation/RepeatClick.java

time: 时间默认0;

unit:单位默认 秒;

key: 默认空字符串

package com.ruoyi.framework.annotation;import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;/*** @author yizhi*/
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface RepeatClick {/*** 时间*/int time() default 0;/*** 时间单位,默认秒*/TimeUnit unit() default TimeUnit.SECONDS;/*** 默认会校验的数据*/String key() default "";
}

2. 添加自定义切面:

代码放置位置:com/ruoyi/framework/aspectj/RepeatClickAspect.java

基于注解和Redis实现防止重复点击

package com.ruoyi.framework.aspectj;import com.ruoyi.common.annotation.RepeatClick;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.extern.log4j.Log4j2;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;import javax.annotation.Resource;
import java.util.UUID;/*** @author yizhi*/
@Aspect
@Component
@Log4j2
public class RepeatClickAspect {@Resourceprivate RedisTemplate<String, Object> redisTemplate;/*** 方式一** @param joinPoint* @param repeatClick* @return* @throws Throwable*/@Around("@annotation(repeatClick)")public Object repeatClick(ProceedingJoinPoint joinPoint, RepeatClick repeatClick) throws Throwable {System.out.println("进入切面了");Object[] args = joinPoint.getArgs();// 重复点击注解为空  跳过if (ObjectUtils.isEmpty(repeatClick)) {return joinPoint.proceed(args);}// 使用错误提示if (ObjectUtils.isEmpty(repeatClick.key()) || repeatClick.time() == 0) {log.error("注意:存在自定义注解,使用异常:请检查是否设置key, time, unit");return joinPoint.proceed(args);}String repeatClickKey = repeatClick.key() + SecurityUtils.getLoginUser().getUserId();if (Boolean.TRUE.equals(redisTemplate.hasKey(repeatClickKey))) {return AjaxResult.error("请勿重复点击");}redisTemplate.opsForValue().set(repeatClickKey, UUID.randomUUID().toString());redisTemplate.expire(repeatClickKey, repeatClick.time(), repeatClick.unit());return joinPoint.proceed(args);}/*** 方式二** @param joinPoint* @return* @throws Throwable*/
//    @Around("@annotation(com.ruoyi.framework.annotation.RepeatClick)")
//    public Object repeatClick(ProceedingJoinPoint joinPoint) throws Throwable {
//        System.out.println("进入切面了");
//        Object[] args = joinPoint.getArgs();
//        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
//        RepeatClick repeatClick = signature.getMethod().getAnnotation(RepeatClick.class);
//        // 重复点击注解为空  跳过
//        if (ObjectUtils.isEmpty(repeatClick)) {
//            return joinPoint.proceed(args);
//        }
//        // 使用错误提示
//        if (ObjectUtils.isEmpty(repeatClick.key()) || repeatClick.time() == 0) {
//            log.error("注意:存在自定义注解,使用异常:请检查是否设置key, time, unit");
//            return joinPoint.proceed(args);
//        }
//        String repeatClickKey = repeatClick.key() + SecurityUtils.getLoginUser().getUserId();
//        if (Boolean.TRUE.equals(redisTemplate.hasKey(repeatClickKey))) {
//            return AjaxResult.error("请勿重复点击");
//        }
//        redisTemplate.opsForValue().set(repeatClickKey, UUID.randomUUID().toString());
//        redisTemplate.expire(repeatClickKey, repeatClick.time(), repeatClick.unit());
//        return joinPoint.proceed(args);
//    }
}

3. 最后在controller中添加注解进行测试

key: 我给自己规定填写 —完整接口名称(因为唯一)

time和unit合起来一起使用,unit默认是秒,那这个就是10秒

如果unit 设置为 分钟,那这个就是十分钟

@RepeatClick(key = "bsLable.ceshi", time = 10)@RepeatClick(key = "bsLable.ceshi", time = 10, unit = TimeUnit.MINUTES)

4. 自行查看测试结果

http://www.hkea.cn/news/450020/

相关文章:

  • 网站建设谈单情景对话青岛seo百科
  • 网站做自适应好不好网页分析报告案例
  • 大连手机自适应网站建设公司seo诊断站长
  • 有哪些好的网站十大电商代运营公司
  • 个人网页设计欣赏网站整站优化快速排名
  • 多少钱立案seo 公司
  • 医学类的网站做Google百度怎么优化排名
  • 手机网站怎样做枸橼酸西地那非片的功效与作用
  • 邯郸做wap网站的公司六六seo基础运营第三讲
  • 六安市建设银行网站seo编辑的工作内容
  • seo外包平台福州百度快照优化
  • 橙子建站广告怎么投放竞价网络推广
  • 中国公司查询网站网络公司起名
  • wordpress邮箱内容更改一键关键词优化
  • 楼市最新消息2022年房价走势seo网络推广经理
  • wordpress免费中文企业主题seo权重优化软件
  • 周口网站建设哪家好济南专业seo推广公司
  • 济南网站忧化怎么把抖音关键词做上去
  • 网站建设与维护的题目网站点击软件排名
  • 网站收录服务企业网络的组网方案
  • nba排名灰色词seo排名
  • 如何建自己的个人网站深圳市seo上词多少钱
  • 迎访问中国建设银行网站_永久免费的电销外呼系统
  • 类似AG网站建设网络营销的十大特点
  • 河北盘古做的网站用的什么服务器品牌策划与推广
  • 做网站开发的是不是程序员品牌营销与推广
  • 安卓android软件seo搜索引擎优化方式
  • 网站设计培训课程引流推广平台
  • 做淘宝美工需要知道的网站app软件推广平台
  • 做自己个人网站搜索竞价