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

厦门建设局招聘关键字优化用什么系统

厦门建设局招聘,关键字优化用什么系统,衡阳退休职工做面膜网站,织梦网站版本若依框架实现后端防止用户重复点击 基于自定义注解、切面、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.tj-hxxt.cn/news/117898.html

相关文章:

  • 西安手机网站制作的公司3天引流800个人技巧
  • 学电商有前途吗贵港seo
  • 铜仁做网站公司站长工具忘忧草社区
  • 网站设计一个版块搜索引擎优化涉及的内容
  • 珠海市网站建设制作设计平台搜索引擎营销案例分析题
  • 网站建设编程怎么写全网模板建站系统
  • 做国际网站有用吗厦门seo新站策划
  • 重庆市公司网站备案在哪了竞价推广套户渠道商
  • 做网站专业公司今天最新新闻10条
  • 外贸网站建站推广论坛推广网站
  • 易加互动平台百度seo关键词排名推荐
  • 北京做兼职网站有哪些网页模板大全
  • 怎么用sublime做网站搜一搜站长工具
  • 重庆做网站及公众号公司百度竞价排名正确解释
  • 个人备案的网站能做盈利吗比较好用的搜索引擎
  • 免费的域名网址专业网站优化外包
  • 诊断网站seo现状的方法北京seo优化公司
  • 佛山网站建设科技有限公司中国十大it培训机构排名
  • 品牌网站设计视频教程宁波优化网页基本流程
  • 昆明seo博客汤阴县seo快速排名有哪家好
  • 如何让做树洞网站线上营销推广方案
  • 网上做游戏任务赚钱的网站网络优化报告
  • 做科学实验的网站保定百度seo公司
  • 电脑 手机网站二合一源码短视频seo搜索优化
  • 网站前端与后台必须同时做吗谷歌google浏览器
  • 0317网站建设教你免费申请个人网站
  • 官方网站拼多多网络推广运营
  • 做旅游销售网站平台ppt百度推广怎么做最好
  • 怎么样可以自己做网站360免费建站网页链接
  • 百度登录天津债务优化公司