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

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

提供專業(yè)網(wǎng)站建設(shè)平臺(tái)收錄是什么意思

提供專業(yè)網(wǎng)站建設(shè)平臺(tái),收錄是什么意思,可以做高清思維導(dǎo)圖的網(wǎng)站,建站 哪個(gè)網(wǎng)站系統(tǒng)好用學(xué)習(xí)的最大理由是想擺脫平庸,早一天就多一份人生的精彩;遲一天就多一天平庸的困擾。各位小伙伴,如果您: 想系統(tǒng)/深入學(xué)習(xí)某技術(shù)知識(shí)點(diǎn)… 一個(gè)人摸索學(xué)習(xí)很難堅(jiān)持,想組團(tuán)高效學(xué)習(xí)… 想寫博客但無從下手,急需…

學(xué)習(xí)的最大理由是想擺脫平庸,早一天就多一份人生的精彩;遲一天就多一天平庸的困擾。各位小伙伴,如果您:
想系統(tǒng)/深入學(xué)習(xí)某技術(shù)知識(shí)點(diǎn)…
一個(gè)人摸索學(xué)習(xí)很難堅(jiān)持,想組團(tuán)高效學(xué)習(xí)…
想寫博客但無從下手,急需寫作干貨注入能量…
熱愛寫作,愿意讓自己成為更好的人…

文章目錄

  • 一、Spring Cache是什么?
  • 二、常用注解
  • 三、使用步驟
    • 1.導(dǎo)入依賴
    • 2.@CachePut的使用
    • 3.@Cacheable的使用
    • 4.@CacheEvict的使用
    • 5.@EnableCaching的使用
  • 總結(jié)


一、Spring Cache是什么?

Spring Cache是一個(gè)框架,實(shí)現(xiàn)了基于注解的緩存功能,只需要簡單地加一個(gè)注解,就能實(shí)現(xiàn)緩存功能。
Spring Cache提供了一層抽象,底層可以切換不同的緩存實(shí)現(xiàn),例如:

  • EHCache
  • Caffeine
  • Redis

二、常用注解

在這里插入圖片描述

三、使用步驟

1.導(dǎo)入依賴

Spring Cache緩存框架的maven導(dǎo)入:

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

Spring Cache緩存中間件的導(dǎo)入:

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

總體pom文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.3</version><relativePath/></parent><groupId>com.itheima</groupId><artifactId>springcache-demo</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>11</maven.compiler.source><maven.compiler.target>11</maven.compiler.target></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><scope>compile</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.20</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.76</version></dependency><dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.6</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-cache</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.2.0</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.1</version></dependency><dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-spring-boot-starter</artifactId><version>3.0.2</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.7.3</version></plugin></plugins></build>
</project>

2.@CachePut的使用

@CachePut:將方法的返回值放到緩存中
案例代碼:

    @PostMapping//@CachePut(cacheNames = "userCache",key = "#user.id")@CachePut(cacheNames = "userCache",key = "#result.id")public User save(@RequestBody User user){userMapper.insert(user);return user;}

其中#這種寫法是spring規(guī)范的。
cacheName:緩存名稱,是個(gè)字符串
key:緩存數(shù)據(jù)
如果使用Spring Cache緩存數(shù)據(jù),key的生成:userCache::緩存數(shù)據(jù)
在這里插入圖片描述
在這里插入圖片描述

3.@Cacheable的使用

@Cacheable:在方法執(zhí)行前先查詢緩存中是否有數(shù)據(jù),如果有數(shù)據(jù),則直接返回緩存數(shù)據(jù);如果沒有緩存數(shù)據(jù),調(diào)用方法并將方法返回值放到緩存中
案例代碼:

    @GetMapping@Cacheable(cacheNames = "userCache",key = "#id")//key的生成:userCache::10public User getById(Long id){User user = userMapper.getById(id);return user;}

4.@CacheEvict的使用

@CacheEvict:將一條或多條數(shù)據(jù)從緩存中刪除
清理一條數(shù)據(jù)案例代碼:

    @DeleteMapping@CacheEvict(cacheNames = "userCache",key="#id")//key的生成:userCache::10public void deleteById(Long id){userMapper.deleteById(id);}

清理多條數(shù)據(jù)(cacheNames定義的名字下的所有數(shù)據(jù)都刪除)案例代碼:

	@DeleteMapping("/delAll")@CacheEvict(cacheNames = "userCache",allEntries = true)public void deleteAll(){userMapper.deleteAll();}

5.@EnableCaching的使用

@EnableCaching:開啟緩存注解功能,通常加在啟動(dòng)類上
案例代碼:

@SpringBootApplication
@EnableTransactionManagement //開啟注解方式的事務(wù)管理
@Slf4j
@EnableCaching//開啟緩存注解功能
public class SkyApplication {public static void main(String[] args) {SpringApplication.run(SkyApplication.class, args);log.info("server started");}
}

總結(jié)

以上就是Spring Cache(緩存框架)的相關(guān)知識(shí)點(diǎn),希望對(duì)你有所幫助。
積跬步以至千里,積怠惰以至深淵。時(shí)代在這跟著你一起努力哦!

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

相關(guān)文章:

  • 心得體會(huì)萬能模板免費(fèi)網(wǎng)站seo
  • 有些網(wǎng)站下方只有版權(quán)沒有ICP簡述seo和sem的區(qū)別與聯(lián)系
  • 北京網(wǎng)站推廣怎么做不屬于網(wǎng)絡(luò)推廣方法
  • 公司網(wǎng)站建設(shè)需要多少錢googleplay官方下載
  • 買2g 空間做下載網(wǎng)站全網(wǎng)搜索關(guān)鍵詞查詢
  • 邯鄲網(wǎng)站設(shè)計(jì)哪家好好省推廣100種方法
  • h5可以用什么網(wǎng)站做app推廣渠道商
  • 幫企業(yè)建網(wǎng)站步驟seo公司杭州
  • 網(wǎng)站設(shè)計(jì)美工多少搜索引擎優(yōu)化大致包含哪些內(nèi)容或環(huán)節(jié)
  • xp怎么做網(wǎng)站服務(wù)器太原做網(wǎng)站的
  • wordpress播放本地mp3seo關(guān)鍵詞排名注冊(cè)價(jià)格
  • 全市網(wǎng)站建設(shè)情況摸底調(diào)查百度網(wǎng)站關(guān)鍵詞排名查詢
  • 網(wǎng)站設(shè)計(jì)制作費(fèi)用多少怎么做互聯(lián)網(wǎng)營銷推廣
  • 南陽東莞網(wǎng)站建設(shè)公司優(yōu)化排名推廣關(guān)鍵詞
  • 網(wǎng)站可以微信支付是怎么做的域名??烤W(wǎng)頁推廣大全
  • 網(wǎng)站定制化開發(fā)介紹新網(wǎng)
  • 哈爾濱網(wǎng)站建設(shè)2017站長統(tǒng)計(jì) 網(wǎng)站統(tǒng)計(jì)
  • 西安做網(wǎng)站朋朋抖音關(guān)鍵詞推廣
  • 商城網(wǎng)站建設(shè)系統(tǒng)企業(yè)網(wǎng)站建設(shè)推廣
  • 免費(fèi)網(wǎng)站推廣軟文發(fā)布中國國家數(shù)據(jù)統(tǒng)計(jì)網(wǎng)
  • 網(wǎng)站備案密碼忘做seo需要哪些知識(shí)
  • 貴州網(wǎng)絡(luò)推廣公司百色seo快速排名
  • 阿里巴巴吧做網(wǎng)站關(guān)鍵詞排名優(yōu)化網(wǎng)站
  • wordpress foxpay企業(yè)站seo報(bào)價(jià)
  • 虛擬主機(jī)能干什么優(yōu)化網(wǎng)站打開速度
  • 確保網(wǎng)站地址沒有做301跳轉(zhuǎn)新網(wǎng)站怎么做推廣
  • 喬拓云智能建站官網(wǎng)登錄入口廈門關(guān)鍵詞排名提升
  • 網(wǎng)站ie不兼容如何開發(fā)網(wǎng)站
  • 唐山市住房城鄉(xiāng)建設(shè)部網(wǎng)站主頁營業(yè)推廣策劃
  • 朝陽網(wǎng)站建設(shè)seo是什么技術(shù)