欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot整合redis+Aop防止重復(fù)提交的實(shí)現(xiàn)

 更新時(shí)間:2023年07月14日 15:19:59   作者:阿A軻  
Spring Boot通過(guò)AOP可以實(shí)現(xiàn)防止表單重復(fù)提交,本文主要介紹了SpringBoot整合redis+Aop防止重復(fù)提交的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

1.redis的安裝

redis下載 解壓 安裝

# wget http://download.redis.io/releases/redis-6.0.8.tar.gz
# tar xzf redis-6.0.8.tar.gz
# cd redis-6.0.8
# make

看一下就會(huì)有

 進(jìn)入redis-6.0.8下的src目錄

[root@VM-16-8-centos redis]# cd redis-6.0.8
[root@VM-16-8-centos redis-6.0.8]# cd src

(  src 目錄下有編譯后的 redis 服務(wù)程序 redis-server,還有用于測(cè)試的客戶(hù)端程序 redis-cli:)

然后啟動(dòng)

# ./redis-server ../redis.conf

redis默認(rèn)端口號(hào) 6379,建議更改。redis.conf是配置文件在  與src是同級(jí)目錄。

要遠(yuǎn)程  #去掉保護(hù)模式,注釋掉bind:127.0.0.1,protected-mode 改為no,

此外就是 redis 安全問(wèn)題需要考慮,不然服務(wù)器會(huì)被入侵被挖礦 ,必須

#設(shè)置密碼 requirepass 你的密碼    (大約在 redis.conf 的 790 行)

設(shè)置密碼后 ,啟動(dòng) redis 服務(wù)進(jìn)程后,就可以使用測(cè)試客戶(hù)端程序 redis-cli 和 redis 服務(wù)交互了

./redis.cli? -p 端口號(hào) -a? 你的密碼

2.SpringBoot整合redis

首先 IDEA 創(chuàng)建好一個(gè)SpringBoot 的 web 項(xiàng)目。

1.導(dǎo)入依賴(lài):

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

2.新建application.yml配置

spring:
  redis:
    # Redis本地服務(wù)器地址,注意要開(kāi)啟redis服務(wù),即那個(gè)redis-server.exe
    host: 你的服務(wù)器地址
    # Redis服務(wù)器端口,默認(rèn)為6379.若有改動(dòng)按改動(dòng)后的來(lái)
    port: 端口號(hào)
    #Redis服務(wù)器連接密碼,默認(rèn)為空,若有設(shè)置按設(shè)置的來(lái)
    password: 密碼
    lettuce:
      pool:
        # 連接池最大連接數(shù),若為負(fù)數(shù)則表示沒(méi)有任何限制
        max-active: 8
        # 連接池最大阻塞等待時(shí)間,若為負(fù)數(shù)則表示沒(méi)有任何限制
        max-wait: -1
        # 連接池中的最大空閑連接
        max-idle: 8

3.redis配置類(lèi)-直接用

 
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
 * redis配置類(lèi)
 */
@Configuration
@EnableCaching //開(kāi)啟注解
public class RedisConfig extends CachingConfigurerSupport {
    /**
     * retemplate相關(guān)配置
     */
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        // 配置連接工廠
        template.setConnectionFactory(factory);
        //使用Jackson2JsonRedisSerializer來(lái)序列化和反序列化redis的value值(默認(rèn)使用JDK的序列化方式)
        Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class);
        ObjectMapper om = new ObjectMapper();
        // 指定要序列化的域,field,get和set,以及修飾符范圍,ANY是都有包括private和public
        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
        // 指定序列化輸入的類(lèi)型,類(lèi)必須是非final修飾的,final修飾的類(lèi),比如String,Integer等會(huì)跑出異常
        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
        jacksonSeial.setObjectMapper(om);
        // 值采用json序列化
        template.setValueSerializer(jacksonSeial);
        //使用StringRedisSerializer來(lái)序列化和反序列化redis的key值
        template.setKeySerializer(new StringRedisSerializer());
        // 設(shè)置hash key 和value序列化模式
        template.setHashKeySerializer(new StringRedisSerializer());
        template.setHashValueSerializer(jacksonSeial);
        template.afterPropertiesSet();
        return template;
    }
    /**
     * 對(duì)hash類(lèi)型的數(shù)據(jù)操作
     */
    @Bean
    public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForHash();
    }
    /**
     * 對(duì)redis字符串類(lèi)型數(shù)據(jù)操作
     */
    @Bean
    public ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForValue();
    }
    /**
     * 對(duì)鏈表類(lèi)型的數(shù)據(jù)操作
     */
    @Bean
    public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForList();
    }
    /**
     * 對(duì)無(wú)序集合類(lèi)型的數(shù)據(jù)操作
     */
    @Bean
    public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForSet();
    }
    /**
     * 對(duì)有序集合類(lèi)型的數(shù)據(jù)操作
     */
    @Bean
    public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForZSet();
    }
}

4.redis工具類(lèi)-直接用

 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@Component
public class RedisUtil {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    public RedisUtil(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }
    /**
     * 指定緩存失效時(shí)間
     * @param key 鍵
     * @param time 時(shí)間(秒)
     * @return
     */
    public boolean expire(String key,long time){
        try {
            if(time>0){
                redisTemplate.expire(key, time, TimeUnit.SECONDS);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 根據(jù)key 獲取過(guò)期時(shí)間
     * @param key 鍵 不能為null
     * @return 時(shí)間(秒) 返回0代表為永久有效
     */
    public long getExpire(String key){
        return redisTemplate.getExpire(key,TimeUnit.SECONDS);
    }
    /**
     * 判斷key是否存在
     * @param key 鍵
     * @return true 存在 false不存在
     */
    public boolean hasKey(String key){
        try {
            return redisTemplate.hasKey(key);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 刪除緩存
     * @param key 可以傳一個(gè)值 或多個(gè)
     */
    @SuppressWarnings("unchecked")
    public void del(String ... key){
        if(key!=null&&key.length>0){
            if(key.length==1){
                redisTemplate.delete(key[0]);
            }else{
                redisTemplate.delete((Collection<String>) CollectionUtils.arrayToList(key));
            }
        }
    }
    //============================String=============================
    /**
     * 普通緩存獲取
     * @param key 鍵
     * @return 值
     */
    public Object get(String key){
        return key==null?null:redisTemplate.opsForValue().get(key);
    }
    /**
     * 普通緩存放入
     * @param key 鍵
     * @param value 值
     * @return true成功 false失敗
     */
    public boolean set(String key,Object value) {
        try {
            redisTemplate.opsForValue().set(key, value);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 普通緩存放入并設(shè)置時(shí)間
     * @param key 鍵
     * @param value 值
     * @param time 時(shí)間(秒) time要大于0 如果time小于等于0 將設(shè)置無(wú)限期
     * @return true成功 false 失敗
     */
    public boolean set(String key,Object value,long time){
        try {
            if(time>0){
                redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
            }else{
                set(key, value);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 遞增
     * @param key 鍵
     * @param delta 要增加幾(大于0)
     * @return
     */
    public long incr(String key, long delta){
        if(delta<0){
            throw new RuntimeException("遞增因子必須大于0");
        }
        return redisTemplate.opsForValue().increment(key, delta);
    }
    /**
     * 遞減
     * @param key 鍵
     * @param delta 要減少幾(小于0)
     * @return
     */
    public long decr(String key, long delta){
        if(delta<0){
            throw new RuntimeException("遞減因子必須大于0");
        }
        return redisTemplate.opsForValue().increment(key, -delta);
    }
    //================================Map=================================
    /**
     * HashGet
     * @param key 鍵 不能為null
     * @param item 項(xiàng) 不能為null
     * @return 值
     */
    public Object hget(String key,String item){
        return redisTemplate.opsForHash().get(key, item);
    }
    /**
     * 獲取hashKey對(duì)應(yīng)的所有鍵值
     * @param key 鍵
     * @return 對(duì)應(yīng)的多個(gè)鍵值
     */
    public Map<Object,Object> hmget(String key){
        return redisTemplate.opsForHash().entries(key);
    }
    /**
     * HashSet
     * @param key 鍵
     * @param map 對(duì)應(yīng)多個(gè)鍵值
     * @return true 成功 false 失敗
     */
    public boolean hmset(String key, Map<String,Object> map){
        try {
            redisTemplate.opsForHash().putAll(key, map);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * HashSet 并設(shè)置時(shí)間
     * @param key 鍵
     * @param map 對(duì)應(yīng)多個(gè)鍵值
     * @param time 時(shí)間(秒)
     * @return true成功 false失敗
     */
    public boolean hmset(String key, Map<String,Object> map, long time){
        try {
            redisTemplate.opsForHash().putAll(key, map);
            if(time>0){
                expire(key, time);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 向一張hash表中放入數(shù)據(jù),如果不存在將創(chuàng)建
     * @param key 鍵
     * @param item 項(xiàng)
     * @param value 值
     * @return true 成功 false失敗
     */
    public boolean hset(String key,String item,Object value) {
        try {
            redisTemplate.opsForHash().put(key, item, value);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 向一張hash表中放入數(shù)據(jù),如果不存在將創(chuàng)建
     * @param key 鍵
     * @param item 項(xiàng)
     * @param value 值
     * @param time 時(shí)間(秒)  注意:如果已存在的hash表有時(shí)間,這里將會(huì)替換原有的時(shí)間
     * @return true 成功 false失敗
     */
    public boolean hset(String key,String item,Object value,long time) {
        try {
            redisTemplate.opsForHash().put(key, item, value);
            if(time>0){
                expire(key, time);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 刪除hash表中的值
     * @param key 鍵 不能為null
     * @param item 項(xiàng) 可以使多個(gè) 不能為null
     */
    public void hdel(String key, Object... item){
        redisTemplate.opsForHash().delete(key,item);
    }
    /**
     * 判斷hash表中是否有該項(xiàng)的值
     * @param key 鍵 不能為null
     * @param item 項(xiàng) 不能為null
     * @return true 存在 false不存在
     */
    public boolean hHasKey(String key, String item){
        return redisTemplate.opsForHash().hasKey(key, item);
    }
    /**
     * hash遞增 如果不存在,就會(huì)創(chuàng)建一個(gè) 并把新增后的值返回
     * @param key 鍵
     * @param item 項(xiàng)
     * @param by 要增加幾(大于0)
     * @return
     */
    public double hincr(String key, String item,double by){
        return redisTemplate.opsForHash().increment(key, item, by);
    }
    /**
     * hash遞減
     * @param key 鍵
     * @param item 項(xiàng)
     * @param by 要減少記(小于0)
     * @return
     */
    public double hdecr(String key, String item,double by){
        return redisTemplate.opsForHash().increment(key, item,-by);
    }
    //============================set=============================
    /**
     * 根據(jù)key獲取Set中的所有值
     * @param key 鍵
     * @return
     */
    public Set<Object> sGet(String key){
        try {
            return redisTemplate.opsForSet().members(key);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 根據(jù)value從一個(gè)set中查詢(xún),是否存在
     * @param key 鍵
     * @param value 值
     * @return true 存在 false不存在
     */
    public boolean sHasKey(String key,Object value){
        try {
            return redisTemplate.opsForSet().isMember(key, value);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 將數(shù)據(jù)放入set緩存
     * @param key 鍵
     * @param values 值 可以是多個(gè)
     * @return 成功個(gè)數(shù)
     */
    public long sSet(String key, Object...values) {
        try {
            return redisTemplate.opsForSet().add(key, values);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
    /**
     * 將set數(shù)據(jù)放入緩存
     * @param key 鍵
     * @param time 時(shí)間(秒)
     * @param values 值 可以是多個(gè)
     * @return 成功個(gè)數(shù)
     */
    public long sSetAndTime(String key,long time,Object...values) {
        try {
            Long count = redisTemplate.opsForSet().add(key, values);
            if(time>0) {
                expire(key, time);
            }
            return count;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
    /**
     * 獲取set緩存的長(zhǎng)度
     * @param key 鍵
     * @return
     */
    public long sGetSetSize(String key){
        try {
            return redisTemplate.opsForSet().size(key);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
    /**
     * 移除值為value的
     * @param key 鍵
     * @param values 值 可以是多個(gè)
     * @return 移除的個(gè)數(shù)
     */
    public long setRemove(String key, Object ...values) {
        try {
            Long count = redisTemplate.opsForSet().remove(key, values);
            return count;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
    //===============================list=================================
    /**
     * 獲取list緩存的內(nèi)容
     * @param key 鍵
     * @param start 開(kāi)始
     * @param end 結(jié)束  0 到 -1代表所有值
     * @return
     */
    public List<Object> lGet(String key, long start, long end){
        try {
            return redisTemplate.opsForList().range(key, start, end);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 獲取list緩存的長(zhǎng)度
     * @param key 鍵
     * @return
     */
    public long lGetListSize(String key){
        try {
            return redisTemplate.opsForList().size(key);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
    /**
     * 通過(guò)索引 獲取list中的值
     * @param key 鍵
     * @param index 索引  index>=0時(shí), 0 表頭,1 第二個(gè)元素,依次類(lèi)推;index<0時(shí),-1,表尾,-2倒數(shù)第二個(gè)元素,依次類(lèi)推
     * @return
     */
    public Object lGetIndex(String key,long index){
        try {
            return redisTemplate.opsForList().index(key, index);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 將list放入緩存
     * @param key 鍵
     * @param value 值
     * @return
     */
    public boolean lSet(String key, Object value) {
        try {
            redisTemplate.opsForList().rightPush(key, value);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 將list放入緩存
     * @param key 鍵
     * @param value 值
     * @param time 時(shí)間(秒)
     * @return
     */
    public boolean lSet(String key, Object value, long time) {
        try {
            redisTemplate.opsForList().rightPush(key, value);
            if (time > 0) {
                expire(key, time);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 將list放入緩存
     * @param key 鍵
     * @param value 值
     * @return
     */
    public boolean lSet(String key, List<Object> value) {
        try {
            redisTemplate.opsForList().rightPushAll(key, value);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 將list放入緩存
     * @param key 鍵
     * @param value 值
     * @param time 時(shí)間(秒)
     * @return
     */
    public boolean lSet(String key, List<Object> value, long time) {
        try {
            redisTemplate.opsForList().rightPushAll(key, value);
            if (time > 0) {
                expire(key, time);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 根據(jù)索引修改list中的某條數(shù)據(jù)
     * @param key 鍵
     * @param index 索引
     * @param value 值
     * @return
     */
    public boolean lUpdateIndex(String key, long index,Object value) {
        try {
            redisTemplate.opsForList().set(key, index, value);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 移除N個(gè)值為value
     * @param key 鍵
     * @param count 移除多少個(gè)
     * @param value 值
     * @return 移除的個(gè)數(shù)
     */
    public long lRemove(String key,long count,Object value) {
        try {
            Long remove = redisTemplate.opsForList().remove(key, count, value);
            return remove;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}

5.寫(xiě)Controller測(cè)試

 
import com.qcby.bootredis.NoRepeatSubmit;
import com.qcby.bootredis.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@Slf4j
@RequestMapping("/redis")
@RestController
public class RedisController {
    @Resource
    private RedisUtil redisUtil;
    @RequestMapping("set")
   // @NoRepeatSubmit
    public boolean redisset(String key, String value){
        System.out.println(key+"--"+value);
        return redisUtil.set(key,value);
    }
    @RequestMapping("get")
    public Object redisget(String key){
        System.out.println(redisUtil.get(key));
        return redisUtil.get(key);
    }
    @RequestMapping("expire")
    public boolean expire(String key,long ExpireTime){
        return redisUtil.expire(key,ExpireTime);
    }
}

6.啟動(dòng)redis,啟動(dòng)程序,存?zhèn)€數(shù)據(jù),測(cè)試結(jié)果

 拿個(gè)數(shù)據(jù):

 redis中:

3.整合AOP,防止重復(fù)提交

一,定義注解

定義一個(gè)鎖住接口時(shí)間的方法,默認(rèn)值為5。

import java.lang.annotation.*;
@Documented
@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface NoRepeatSubmit {
    int lockTime() default 5;
}

二,寫(xiě)一個(gè)HttpContextUtil工具類(lèi)獲取HttpServletRequest請(qǐng)求

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Objects;
public class HttpContextUtils {
    public static HttpServletRequest HttpServletRequest(){
        return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
    }
}

三,定義一個(gè)切面

采用的方案是Redis來(lái)緩存提交接口的唯一標(biāo)識(shí),然后設(shè)置過(guò)期時(shí)間。

唯一標(biāo)識(shí)使用接口的URL和用戶(hù)的token組合在一起的方式使達(dá)到唯一。用戶(hù)每發(fā)起第一次添加請(qǐng)求,會(huì)經(jīng)過(guò)界面,在切面獲取信息后組裝起來(lái)存入Redis,當(dāng)用戶(hù)后續(xù)發(fā)起請(qǐng)求時(shí),首先判斷Redis中是否緩存了這個(gè)key,如果緩存了,則證明已經(jīng)提交,于是反饋給前端,如果不存在,證明沒(méi)有提交,則存入Redis。

@Component
@Aspect
public class NoRepeatSubmitAspect {
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Pointcut("@annotation(repeatSubmit)")
    public void pointcutNoRepeat(NoRepeatSubmit repeatSubmit){};
    @Around("pointcutNoRepeat(noRepeatSubmit)")
    public Object doNoRepeat(ProceedingJoinPoint point,NoRepeatSubmit noRepeatSubmit) throws Throwable {
        int i=noRepeatSubmit.lockTime();
        HttpServletRequest httpServletRequest = HttpContextUtils.HttpServletRequest();
        String token = httpServletRequest.getHeader("token");
        String url = httpServletRequest.getRequestURL().toString();
        String sign = url+"/"+token;
        Boolean key=redisTemplate.hasKey(sign);
        if (key){
            throw new Exception("請(qǐng)勿重復(fù)提交");
        }
        redisTemplate.opsForValue().set(sign,sign,i,TimeUnit.SECONDS);
        return  point.proceed();
    }
}

如果key存在拋出異常。 @Aspect:聲明這是一個(gè)切面類(lèi)(使用時(shí)需要與@Component注解一起用,表明同時(shí)將該類(lèi)交給spring管理)@pointcut(@annotation)是Spring AOP中的一個(gè)注解,它可以用來(lái)指定一個(gè)切點(diǎn),該切點(diǎn)選擇所有帶有特定注解的方法或類(lèi)。例如,如果我們想要記錄所有帶有@Log注解的方法的日志,我們可以定義一個(gè)切點(diǎn),使用@pointcut(@annotation(Log.class)注解來(lái)選擇這些方法。

@Around 環(huán)繞通知

 point.proceed():

  • 環(huán)繞通知 ProceedingJoinPoint 執(zhí)行proceed方法的作用是讓目標(biāo)方法執(zhí)行,這也是環(huán)繞通知和前置、后置通知方法的一個(gè)最大區(qū)別。
  • 簡(jiǎn)單理解,環(huán)繞通知=前置+目標(biāo)方法執(zhí)行+后置通知,proceed方法就是用于啟動(dòng)目標(biāo)方法執(zhí)行的.

四。之前方法上加上我們的注解 

 結(jié)果:第一次,添加完成,緊接著第二次發(fā)送,拋出了我們的異常

參考鏈接:http://www.dbjr.com.cn/program/291739flp.htm

到此這篇關(guān)于SpringBoot整合redis+Aop防止重復(fù)提交的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)SpringBoot redis Aop防重復(fù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 如何把VS Code打造成Java開(kāi)發(fā)IDE

    如何把VS Code打造成Java開(kāi)發(fā)IDE

    這篇文章主要介紹了如何把VS Code打造成Java開(kāi)發(fā)IDE,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Java實(shí)現(xiàn)一個(gè)簡(jiǎn)易版的多級(jí)菜單功能

    Java實(shí)現(xiàn)一個(gè)簡(jiǎn)易版的多級(jí)菜單功能

    這篇文章主要給大家介紹了關(guān)于Java如何實(shí)現(xiàn)一個(gè)簡(jiǎn)易版的多級(jí)菜單功能的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-01-01
  • 基于SpringBoot和Vue3的博客平臺(tái)文章列表與分頁(yè)功能實(shí)現(xiàn)

    基于SpringBoot和Vue3的博客平臺(tái)文章列表與分頁(yè)功能實(shí)現(xiàn)

    在前面的教程中,我們已經(jīng)實(shí)現(xiàn)了基于Spring Boot和Vue3的發(fā)布、編輯、刪除文章功能。本教程將繼續(xù)引導(dǎo)您實(shí)現(xiàn)博客平臺(tái)的文章列表與分頁(yè)功能,需要的朋友可以參考閱讀
    2023-04-04
  • Springboot中使用Filter實(shí)現(xiàn)Header認(rèn)證詳解

    Springboot中使用Filter實(shí)現(xiàn)Header認(rèn)證詳解

    這篇文章主要介紹了Springboot中使用Filter實(shí)現(xiàn)Header認(rèn)證詳解,當(dāng)在?web.xml?注冊(cè)了一個(gè)?Filter?來(lái)對(duì)某個(gè)?Servlet?程序進(jìn)行攔截處理時(shí),它可以決定是否將請(qǐng)求繼續(xù)傳遞給?Servlet?程序,以及對(duì)請(qǐng)求和響應(yīng)消息是否進(jìn)行修改,需要的朋友可以參考下
    2023-08-08
  • HttpClient HttpRoutePlanner接口確定請(qǐng)求目標(biāo)路由

    HttpClient HttpRoutePlanner接口確定請(qǐng)求目標(biāo)路由

    這篇文章主要為大家介紹了使用HttpClient HttpRoutePlanner接口確定請(qǐng)求目標(biāo)路由,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-10-10
  • SpringBoot使用validation進(jìn)行自參數(shù)校驗(yàn)的方法

    SpringBoot使用validation進(jìn)行自參數(shù)校驗(yàn)的方法

    在SpringBoot項(xiàng)目中,利用validation依賴(lài)可以通過(guò)注解方式校驗(yàn)數(shù)據(jù)庫(kù)交互參數(shù),提高代碼可讀性和維護(hù)性,此方法避免了硬編碼校驗(yàn)規(guī)則,方便后期規(guī)則變更,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-09-09
  • 在Spring?Boot中啟用HTTPS的方法

    在Spring?Boot中啟用HTTPS的方法

    本文介紹了在Spring Boot項(xiàng)目中啟用HTTPS的步驟,從生成SSL證書(shū)開(kāi)始,到配置Spring Boot。HTTPS是保護(hù)Web應(yīng)用程序安全的基石之一,而Spring Boot則提供了相對(duì)簡(jiǎn)易的途徑來(lái)配置它,感興趣的朋友跟隨小編一起看看吧
    2024-02-02
  • Eclipse中自動(dòng)添加注釋?zhuān)▋煞N)

    Eclipse中自動(dòng)添加注釋?zhuān)▋煞N)

    本文主要介紹了Eclipse中自動(dòng)添加注釋的兩種方法。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-02-02
  • mybatis對(duì)于list更新sql語(yǔ)句的寫(xiě)法說(shuō)明

    mybatis對(duì)于list更新sql語(yǔ)句的寫(xiě)法說(shuō)明

    這篇文章主要介紹了mybatis對(duì)于list更新sql語(yǔ)句的寫(xiě)法說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • JavaWeb實(shí)戰(zhàn)之編寫(xiě)單元測(cè)試類(lèi)測(cè)試數(shù)據(jù)庫(kù)操作

    JavaWeb實(shí)戰(zhàn)之編寫(xiě)單元測(cè)試類(lèi)測(cè)試數(shù)據(jù)庫(kù)操作

    這篇文章主要介紹了JavaWeb實(shí)戰(zhàn)之編寫(xiě)單元測(cè)試類(lèi)測(cè)試數(shù)據(jù)庫(kù)操作,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)javaweb的小伙伴們有很大的幫助,需要的朋友可以參考下
    2021-04-04

最新評(píng)論