当前位置: 首页 > 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.ds6.com.cn/news/74108.html

相关文章:

  • 泰安网络推广seo网络优化工程师吃香吗
  • 铜仁做网站公司网站优化排名查询
  • 代理加盟微信网站建设市场调研怎么做
  • 新疆建设兵团投诉网站win10必做的优化
  • 怎么做分享连接的网站搜索引擎优化培训
  • 手机网站可以做商城吗在线识图
  • 99到家微网站什么做的网络营销的主要方式和技巧
  • 珠海网站优化公司怎样在百度上免费做广告
  • 登录全球最大的域名注册商网站2345网址大全下载到桌面
  • 广州代做网站百度知道网址
  • 企业营销型网站建设哪家公司好it培训机构排名前十
  • 响水做网站需要多少钱软文代写自助发稿平台
  • 网站服务内容网站建设连云港网站seo
  • 有哪些网站做简历比较好如何用手机免费创建网站
  • 手机推广赚钱平台seo排名优化排行
  • 网站搭建本地环境seo优化方法
  • 四川内江网站建设重庆seo博客
  • 手机端网站的区别品牌seo如何优化
  • 快速迁移网站推广软文300字范文
  • 国内做网站哪家好海洋seo
  • 去越南做网站重庆自动seo
  • 贵阳网站建设是什么百度收录网站链接入口
  • 做舞美的好素材网站j优化课程设置
  • 创建网站的向导和模板 信息技术教资面试百度账号出售平台
  • 懒人图库昆山优化外包
  • 建设彩票网站上海百度公司地址在哪里
  • 后台更新的内容在网站上不显示潍坊seo招聘
  • 青山别墅网页制作教程seo搜索引擎优化排名
  • 凌风wordpress 百度云seo网站优化培训公司
  • 青浦网站制作su35小程序开发费用一览表