中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

廈門建設(shè)局葉文語(yǔ)簡(jiǎn)歷優(yōu)化搜索曝光次數(shù)的方法

廈門建設(shè)局葉文語(yǔ)簡(jiǎn)歷,優(yōu)化搜索曝光次數(shù)的方法,六安網(wǎng)站推廣獲客app,低價(jià)網(wǎng)站建設(shè)費(fèi)用多少若依框架實(shí)現(xiàn)后端防止用戶重復(fù)點(diǎn)擊 基于自定義注解、切面、Redis實(shí)現(xiàn) 1. 添加自定義注解: 代碼放置位置:com/ruoyi/common/annotation/RepeatClick.java time: 時(shí)間默認(rèn)0; unit:單位默認(rèn) 秒; key: 默認(rèn)空字符串 package com.ruoyi.fra…

若依框架實(shí)現(xiàn)后端防止用戶重復(fù)點(diǎn)擊

基于自定義注解、切面、Redis實(shí)現(xiàn)

1. 添加自定義注解:

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

time: 時(shí)間默認(rèn)0;

unit:單位默認(rèn) 秒;

key: 默認(rèn)空字符串

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 {/*** 時(shí)間*/int time() default 0;/*** 時(shí)間單位,默認(rèn)秒*/TimeUnit unit() default TimeUnit.SECONDS;/*** 默認(rèn)會(huì)校驗(yàn)的數(shù)據(jù)*/String key() default "";
}

2. 添加自定義切面:

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

基于注解和Redis實(shí)現(xiàn)防止重復(fù)點(diǎn)擊

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("進(jìn)入切面了");Object[] args = joinPoint.getArgs();// 重復(fù)點(diǎn)擊注解為空  跳過(guò)if (ObjectUtils.isEmpty(repeatClick)) {return joinPoint.proceed(args);}// 使用錯(cuò)誤提示if (ObjectUtils.isEmpty(repeatClick.key()) || repeatClick.time() == 0) {log.error("注意:存在自定義注解,使用異常:請(qǐng)檢查是否設(shè)置key, time, unit");return joinPoint.proceed(args);}String repeatClickKey = repeatClick.key() + SecurityUtils.getLoginUser().getUserId();if (Boolean.TRUE.equals(redisTemplate.hasKey(repeatClickKey))) {return AjaxResult.error("請(qǐng)勿重復(fù)點(diǎn)擊");}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("進(jìn)入切面了");
//        Object[] args = joinPoint.getArgs();
//        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
//        RepeatClick repeatClick = signature.getMethod().getAnnotation(RepeatClick.class);
//        // 重復(fù)點(diǎn)擊注解為空  跳過(guò)
//        if (ObjectUtils.isEmpty(repeatClick)) {
//            return joinPoint.proceed(args);
//        }
//        // 使用錯(cuò)誤提示
//        if (ObjectUtils.isEmpty(repeatClick.key()) || repeatClick.time() == 0) {
//            log.error("注意:存在自定義注解,使用異常:請(qǐng)檢查是否設(shè)置key, time, unit");
//            return joinPoint.proceed(args);
//        }
//        String repeatClickKey = repeatClick.key() + SecurityUtils.getLoginUser().getUserId();
//        if (Boolean.TRUE.equals(redisTemplate.hasKey(repeatClickKey))) {
//            return AjaxResult.error("請(qǐng)勿重復(fù)點(diǎn)擊");
//        }
//        redisTemplate.opsForValue().set(repeatClickKey, UUID.randomUUID().toString());
//        redisTemplate.expire(repeatClickKey, repeatClick.time(), repeatClick.unit());
//        return joinPoint.proceed(args);
//    }
}

3. 最后在controller中添加注解進(jìn)行測(cè)試

key: 我給自己規(guī)定填寫 —完整接口名稱(因?yàn)槲ㄒ?#xff09;

time和unit合起來(lái)一起使用,unit默認(rèn)是秒,那這個(gè)就是10秒

如果unit 設(shè)置為 分鐘,那這個(gè)就是十分鐘

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

4. 自行查看測(cè)試結(jié)果

http://www.risenshineclean.com/news/8721.html

相關(guān)文章:

  • 互聯(lián)網(wǎng)金融p2p網(wǎng)站建設(shè)模板網(wǎng)站數(shù)據(jù)統(tǒng)計(jì)
  • 國(guó)外網(wǎng)站頁(yè)面做多大傳統(tǒng)營(yíng)銷與網(wǎng)絡(luò)營(yíng)銷的區(qū)別
  • 學(xué)網(wǎng)站建設(shè)好嗎seo百科
  • 臨沂做網(wǎng)站推廣的公司有瀏陽(yáng)廖主任打人案
  • 廣州開發(fā)區(qū)建設(shè)和環(huán)境保護(hù)網(wǎng)站網(wǎng)站seo運(yùn)營(yíng)
  • 十九歲日本電影免費(fèi)完整版觀看天津seo數(shù)據(jù)監(jiān)控
  • 如果做網(wǎng)站推廣深圳網(wǎng)站開發(fā)技術(shù)
  • 網(wǎng)站二級(jí)頁(yè)面做哪些東西百度網(wǎng)址大全舊版安裝
  • wordpress新聞網(wǎng)站南昌seo營(yíng)銷
  • 上海模板建站多少錢國(guó)內(nèi)十大4a廣告公司
  • 自己做的網(wǎng)站不備案行嗎手機(jī)關(guān)鍵詞seo排名優(yōu)化
  • 電子商務(wù)網(wǎng)站業(yè)務(wù)流程網(wǎng)站域名解析ip查詢
  • 咸陽(yáng)做網(wǎng)站電話青島網(wǎng)站建設(shè)方案
  • 有幾家做網(wǎng)站的公司好谷歌商店paypal官網(wǎng)下載
  • 東莞網(wǎng)站營(yíng)銷推廣公司鄭州seo培訓(xùn)班
  • 網(wǎng)站建設(shè)合同前期需注意哪些問(wèn)題百度app登錄
  • wordpress怎么被百度收錄福州seo按天收費(fèi)
  • 做軟件的網(wǎng)站情感營(yíng)銷的十大案例
  • 哪個(gè)網(wǎng)站可以做服裝批發(fā)站內(nèi)優(yōu)化包括哪些
  • 網(wǎng)頁(yè)制作免費(fèi)網(wǎng)站建設(shè)的搜索引擎優(yōu)化
  • 網(wǎng)站開發(fā)項(xiàng)目的wbsseo文章關(guān)鍵詞怎么優(yōu)化
  • 做puzzle的網(wǎng)站香飄飄奶茶軟文
  • 深圳布吉網(wǎng)站建設(shè)百度指數(shù)官網(wǎng)移動(dòng)版
  • 成都工裝裝修設(shè)計(jì)公司seo站外優(yōu)化平臺(tái)
  • org網(wǎng)站建設(shè)廣告外鏈購(gòu)買交易平臺(tái)
  • 溫州專業(yè)網(wǎng)站托管網(wǎng)絡(luò)熱詞的利弊
  • 網(wǎng)站成立時(shí)間搜索優(yōu)化軟件
  • 建設(shè)網(wǎng)站代碼電商熱門關(guān)鍵詞
  • 眉山手機(jī)網(wǎng)站建設(shè)每天4元代發(fā)廣告
  • 廣州建設(shè)工程交易中心改版seo推廣公司排名