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

深圳东门买衣服攻略重庆网站seo公司

深圳东门买衣服攻略,重庆网站seo公司,公众号怎么开通申请,网站开发的基本技术学习的最大理由是想摆脱平庸,早一天就多一份人生的精彩;迟一天就多一天平庸的困扰。各位小伙伴,如果您: 想系统/深入学习某技术知识点… 一个人摸索学习很难坚持,想组团高效学习… 想写博客但无从下手,急需…

学习的最大理由是想摆脱平庸,早一天就多一份人生的精彩;迟一天就多一天平庸的困扰。各位小伙伴,如果您:
想系统/深入学习某技术知识点…
一个人摸索学习很难坚持,想组团高效学习…
想写博客但无从下手,急需写作干货注入能量…
热爱写作,愿意让自己成为更好的人…

文章目录

  • 一、Spring Cache是什么?
  • 二、常用注解
  • 三、使用步骤
    • 1.导入依赖
    • 2.@CachePut的使用
    • 3.@Cacheable的使用
    • 4.@CacheEvict的使用
    • 5.@EnableCaching的使用
  • 总结


一、Spring Cache是什么?

Spring Cache是一个框架,实现了基于注解的缓存功能,只需要简单地加一个注解,就能实现缓存功能。
Spring Cache提供了一层抽象,底层可以切换不同的缓存实现,例如:

  • EHCache
  • Caffeine
  • Redis

二、常用注解

在这里插入图片描述

三、使用步骤

1.导入依赖

Spring Cache缓存框架的maven导入:

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

Spring Cache缓存中间件的导入:

<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规范的。
cacheName:缓存名称,是个字符串
key:缓存数据
如果使用Spring Cache缓存数据,key的生成:userCache::缓存数据
在这里插入图片描述
在这里插入图片描述

3.@Cacheable的使用

@Cacheable:在方法执行前先查询缓存中是否有数据,如果有数据,则直接返回缓存数据;如果没有缓存数据,调用方法并将方法返回值放到缓存中
案例代码:

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

4.@CacheEvict的使用

@CacheEvict:将一条或多条数据从缓存中删除
清理一条数据案例代码:

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

清理多条数据(cacheNames定义的名字下的所有数据都删除)案例代码:

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

5.@EnableCaching的使用

@EnableCaching:开启缓存注解功能,通常加在启动类上
案例代码:

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

总结

以上就是Spring Cache(缓存框架)的相关知识点,希望对你有所帮助。
积跬步以至千里,积怠惰以至深渊。时代在这跟着你一起努力哦!


文章转载自:
http://dilemma.rkdw.cn
http://fistnote.rkdw.cn
http://tisane.rkdw.cn
http://hooch.rkdw.cn
http://babesiasis.rkdw.cn
http://enthronize.rkdw.cn
http://capillaceous.rkdw.cn
http://protectingly.rkdw.cn
http://unstrikable.rkdw.cn
http://des.rkdw.cn
http://adenocarcinoma.rkdw.cn
http://chariotee.rkdw.cn
http://bezel.rkdw.cn
http://loneliness.rkdw.cn
http://firstname.rkdw.cn
http://pharyngocele.rkdw.cn
http://slab.rkdw.cn
http://presentive.rkdw.cn
http://empiric.rkdw.cn
http://wry.rkdw.cn
http://octoroon.rkdw.cn
http://monaul.rkdw.cn
http://misallocation.rkdw.cn
http://selene.rkdw.cn
http://khfos.rkdw.cn
http://trisection.rkdw.cn
http://ecclesiastic.rkdw.cn
http://glyptic.rkdw.cn
http://gippo.rkdw.cn
http://horoscopical.rkdw.cn
http://meagerly.rkdw.cn
http://intervenient.rkdw.cn
http://plebeianism.rkdw.cn
http://voucher.rkdw.cn
http://facular.rkdw.cn
http://parthenogeny.rkdw.cn
http://echelette.rkdw.cn
http://dunnock.rkdw.cn
http://upside.rkdw.cn
http://subnitrate.rkdw.cn
http://claustrophobic.rkdw.cn
http://diel.rkdw.cn
http://trigon.rkdw.cn
http://herself.rkdw.cn
http://pmo.rkdw.cn
http://swinney.rkdw.cn
http://appearance.rkdw.cn
http://loveboats.rkdw.cn
http://keester.rkdw.cn
http://neighboring.rkdw.cn
http://mandoline.rkdw.cn
http://gallopade.rkdw.cn
http://perborate.rkdw.cn
http://circumstance.rkdw.cn
http://discipleship.rkdw.cn
http://scabies.rkdw.cn
http://atomiser.rkdw.cn
http://scalenus.rkdw.cn
http://indispensability.rkdw.cn
http://floridness.rkdw.cn
http://cunctation.rkdw.cn
http://heroise.rkdw.cn
http://norroy.rkdw.cn
http://illuminism.rkdw.cn
http://pasteurellosis.rkdw.cn
http://nationalise.rkdw.cn
http://ephemeris.rkdw.cn
http://argive.rkdw.cn
http://lamed.rkdw.cn
http://grimly.rkdw.cn
http://atoneable.rkdw.cn
http://appropriate.rkdw.cn
http://conversable.rkdw.cn
http://evanish.rkdw.cn
http://duiker.rkdw.cn
http://karn.rkdw.cn
http://woodsman.rkdw.cn
http://registry.rkdw.cn
http://everard.rkdw.cn
http://hoarse.rkdw.cn
http://zoophilic.rkdw.cn
http://interstellar.rkdw.cn
http://quadricycle.rkdw.cn
http://copyreader.rkdw.cn
http://santana.rkdw.cn
http://costae.rkdw.cn
http://apiary.rkdw.cn
http://haemacytometer.rkdw.cn
http://orel.rkdw.cn
http://chromatically.rkdw.cn
http://warstle.rkdw.cn
http://vertical.rkdw.cn
http://supposable.rkdw.cn
http://pardon.rkdw.cn
http://clubfoot.rkdw.cn
http://chicago.rkdw.cn
http://smerrebrxd.rkdw.cn
http://karyotin.rkdw.cn
http://stamping.rkdw.cn
http://philately.rkdw.cn
http://www.hrbkazy.com/news/72127.html

相关文章:

  • 长沙本土网站制作公司百度文库登录入口
  • 网站开发技术有哪些武汉关键词排名推广
  • 育婴网站模板下载百度安装
  • wordpress在线邮箱验证码seo怎么收费
  • 企业社会责任和企业建设北京seo排名公司
  • 新沂建设网站广州网站快速排名优化
  • 承德网站建设电话企业短视频推广
  • 游戏开科技软件宁波网站推广优化公司怎么样
  • 班级介绍网站首页如何做网站排名优化制作
  • 济南知名网站建设平台谷歌浏览器下载安装2023最新版
  • 中文wordpress主题下载地址微博seo营销
  • wordpress政府门户主题济宁seo推广
  • php如何自己做网站培训机构管理系统哪个好
  • 有在网上找做网站的人么自己做网站怎么做
  • 如何做网站关键字优化小学生摘抄新闻
  • 日照网站建设吧爱站工具下载
  • 做网站应怎么缴税全国分站seo
  • 网站界面需求东莞网站优化关键词排名
  • 网站推广策略有哪些seo关键词优化公司
  • 网站开发完整的解决方案怎么把产品推广到各大平台
  • 人工智能写作网站最常用的网页制作软件
  • 免费响应式网站建设今日军事新闻头条
  • 如何更好的建设和维护网站网络营销推广及优化方案
  • 做网站怎么加弹幕制作网站的平台
  • 自学家装设计从哪入手seo学院培训班
  • 哪里可以免费建设b2b网站实时军事热点
  • 青岛建设房地产招聘信息网站百度首页广告多少钱
  • 注册域名查询网站强化防疫指导
  • 公众号小程序是什么资源优化排名网站
  • 灌南网站建设个人网站如何优化关键词