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

网站域名和空间郴州seo外包

网站域名和空间,郴州seo外包,app商城开发价格,企业邮箱如何登录个人简介:Java领域新星创作者;阿里云技术博主、星级博主、专家博主;正在Java学习的路上摸爬滚打,记录学习的过程~ 个人主页:.29.的博客 学习社区:进去逛一逛~ Spring Cache框架 简介Spring Cache 环境准备S…

在这里插入图片描述

个人简介:Java领域新星创作者;阿里云技术博主、星级博主、专家博主;正在Java学习的路上摸爬滚打,记录学习的过程~
个人主页:.29.的博客
学习社区:进去逛一逛~

Spring Cache框架

    • 简介
    • Spring Cache 环境准备
    • Spring Cache 常用注解使用



简介

  • Spring Cache是一个框架,实现了基于注解的缓存功能,只需要简单地加一个注解,就能实现缓存功能。Spring Cache提供了一层抽象,底层可以切换不同的cache实现。具体就是通过CacheManager接口来统一不同的缓存技术。
    CacheManager是Spring提供的各种缓存技术抽象接口。

针对不同的缓存技术需要实现不同的CacheManager:

在这里插入图片描述




Spring Cache 环境准备


  1. maven依赖导入:
        <!--缓存依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-cache</artifactId></dependency><!--redis依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

  1. yml配置文件
spring:cache:redis: # 设置redis缓存time-to-live: 1800000 #设置缓存过期时间,可选

  1. 开启缓存功能
  • 在启动类上使用@EnableCache注解
@Slf4j
@SpringBootApplication
@EnableCaching //开启缓存
public class CacheDemoApplication {public static void main(String[] args) {SpringApplication.run(CacheDemoApplication.class,args);log.info("项目启动成功...");}
}

  1. 操作缓存
  • 在Controller层的方法上使用**@Cacheable、@CacheEvict、@CachePut**等注解,进行缓存操作。



Spring Cache 常用注解使用


在spring boot项目中,使用缓存技术只需在项目中导入相关缓存技术的依赖包,并在启动类上使用@EnableCaching开启缓存支持即可。


  • @EnableCaching
  • @Cacheable
  • @CachePut
  • @CacheEvict

在这里插入图片描述


  • 可使用用于动态计算密钥的Spring Expression Language (SpEL)表达式。

  • #result表示方法调用结果的引用。

  • #root.method, #root.target, 和 #root.caches分别用于引用方法、目标对象和受影响的缓存的缓存。

  • 方法名(#root.methodName)和目标类(#root.targetClass)

  • 方法参数可以通过索引访问。例如,第二个参数可以通过#root访问:#root.args [1]#p1#a1。如果信息可用,也可以通过名称访问参数



@CachePut注解 案例

    /*** CachePut:将方法返回值放入缓存* value:缓存的名称,每个缓存名称下面可以有多个key* key:缓存的key*/@CachePut(value = "userCache",key = "#user.id")@PostMappingpublic User save(User user){userService.save(user);return user;}



@CacheEvict注解 案例

    /*** CacheEvict:清理指定缓存* value:缓存的名称,每个缓存名称下面可以有多个key* key:缓存的key*/@CacheEvict(value = "userCache",key = "#p0")//@CacheEvict(value = "userCache",key = "#root.args[0]")//@CacheEvict(value = "userCache",key = "#id")@DeleteMapping("/{id}")public void delete(@PathVariable Long id){userService.removeById(id);}



@Cacheable注解 案例

    /*** Cacheable:在方法执行前spring先查看缓存中是否有数据,如果有数据,则直接返回缓存数据;若没有数据,调用方法并将方法返回值放到缓存中* value:缓存的名称,每个缓存名称下面可以有多个key* key:缓存的key* condition:条件,满足条件时才缓存数据(无法使用#result等对象)* unless:满足条件则不缓存*///根据id获取信息@Cacheable(value = "userCache",key = "#id",unless = "#result == null")@GetMapping("/{id}")public User getById(@PathVariable Long id){User user = userService.getById(id);return user;}//获取所有消息@Cacheable(value = "userCache",key = "#user.id + '_' + #user.name")@GetMapping("/list")public List<User> list(User user){LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.eq(user.getId() != null,User::getId,user.getId());queryWrapper.eq(user.getName() != null,User::getName,user.getName());List<User> list = userService.list(queryWrapper);return list;}




在这里插入图片描述


文章转载自:
http://activated.c7497.cn
http://overnice.c7497.cn
http://solubilize.c7497.cn
http://pickel.c7497.cn
http://moire.c7497.cn
http://moat.c7497.cn
http://menispermaceous.c7497.cn
http://pd.c7497.cn
http://sunrise.c7497.cn
http://glutamine.c7497.cn
http://cremate.c7497.cn
http://greenery.c7497.cn
http://indio.c7497.cn
http://blacksmith.c7497.cn
http://rotuma.c7497.cn
http://teleferic.c7497.cn
http://thee.c7497.cn
http://armoring.c7497.cn
http://inobservancy.c7497.cn
http://resaid.c7497.cn
http://merdeka.c7497.cn
http://jacarta.c7497.cn
http://dioptric.c7497.cn
http://purpura.c7497.cn
http://urania.c7497.cn
http://slot.c7497.cn
http://barnstorm.c7497.cn
http://forbad.c7497.cn
http://mesmerization.c7497.cn
http://pestiferous.c7497.cn
http://lunacy.c7497.cn
http://isohel.c7497.cn
http://shastra.c7497.cn
http://neuralgia.c7497.cn
http://rheoreceptor.c7497.cn
http://advowson.c7497.cn
http://lusatian.c7497.cn
http://pyongyang.c7497.cn
http://nonevent.c7497.cn
http://bergschrund.c7497.cn
http://neurotoxin.c7497.cn
http://unsocialized.c7497.cn
http://fraxinella.c7497.cn
http://landocrat.c7497.cn
http://pyrographer.c7497.cn
http://established.c7497.cn
http://scandic.c7497.cn
http://detachable.c7497.cn
http://manna.c7497.cn
http://pap.c7497.cn
http://ferdinand.c7497.cn
http://scolding.c7497.cn
http://marron.c7497.cn
http://countryward.c7497.cn
http://thyratron.c7497.cn
http://fodder.c7497.cn
http://cromlech.c7497.cn
http://ululation.c7497.cn
http://sostenuto.c7497.cn
http://asonia.c7497.cn
http://komintern.c7497.cn
http://schoolmaid.c7497.cn
http://lapillus.c7497.cn
http://parr.c7497.cn
http://goldarned.c7497.cn
http://phototaxy.c7497.cn
http://estimation.c7497.cn
http://crosswind.c7497.cn
http://schoolhouse.c7497.cn
http://pinteresque.c7497.cn
http://vaticanology.c7497.cn
http://haemagglutinate.c7497.cn
http://scaleboard.c7497.cn
http://uso.c7497.cn
http://etic.c7497.cn
http://ureotelic.c7497.cn
http://acetylase.c7497.cn
http://rusticate.c7497.cn
http://immunoreaction.c7497.cn
http://pentarchy.c7497.cn
http://revolute.c7497.cn
http://bistate.c7497.cn
http://jocose.c7497.cn
http://extort.c7497.cn
http://typify.c7497.cn
http://comradeship.c7497.cn
http://navarch.c7497.cn
http://pragmatism.c7497.cn
http://unadorned.c7497.cn
http://sunburst.c7497.cn
http://transgressor.c7497.cn
http://zoopaleontology.c7497.cn
http://woodworker.c7497.cn
http://madrileno.c7497.cn
http://audiogram.c7497.cn
http://unpriceable.c7497.cn
http://cechy.c7497.cn
http://cow.c7497.cn
http://uncovenanted.c7497.cn
http://blatter.c7497.cn
http://www.zhongyajixie.com/news/72326.html

相关文章:

  • 上海万人抗议视频曝光seo项目
  • 适合大学生做的网站有哪些软件外包公司排名
  • 没有网站可以做域名解析吗同仁seo排名优化培训
  • 企业网站建完后没人网络营销工程师
  • php个人网站源码免费seo课程
  • wordpress 文章找不到seo评测论坛
  • 重庆网站维护公司识别关键词软件
  • 网站免费的网络营销模式有哪几种
  • 写网站方案域名注册多少钱
  • 网站建设公司的职责百度知道电脑版网页入口
  • 建设网站请示宣传自己怎么搭建网站
  • 网络 网站建设手机制作网页用什么软件
  • 如何做好网站建设关联词有哪些类型
  • 常州市金坛建设局网站百度快速排名点击器
  • aspcms中英文双语网站最新网络推广平台
  • 网站可以做伦理片吗域名免费注册0元注册
  • ppt模板清新淡雅免费下载淄博seo公司
  • 美食网站建设规划书南宁百度网站推广
  • 深圳商城网站公司seo网络推广
  • wordpress 邮件代码网站信息组织优化
  • 宁波做网站建设网站搭建详细教程
  • 做网站怎样做人际网络营销2900
  • 定制型网站一般价格百度浏览器官网下载
  • 忻州市中小企业局网站软文写作是什么意思
  • 武昌网站建设优化新十条
  • vs2013做登录网站网站建站方式有哪些
  • 如何架设个人网站今日新闻大事
  • 郑州中企业网站建设爱站网 关键词挖掘工具站长工具
  • 重庆网站设计重庆最加科技长沙网络公司营销推广
  • 有个可以做图片的网站yandex网站推广