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

阜宁做网站工作室中小企业网站制作报价

阜宁做网站工作室,中小企业网站制作报价,在线阅读小说网站怎么做,沈阳创新网站建设报价前言 上文我们做了在Spring Boot下对Redis的基本操作,如果频繁对Redis进行操作而写对应的方法显示使用注释更会更高效; 比如: 依之前操作对一个业务进行定入缓存需要把数据拉取到后再定入; 而今天我们可以通过注释的方式不需要额外…

前言

上文我们做了在Spring Boot下对Redis的基本操作,如果频繁对Redis进行操作而写对应的方法显示使用注释更会更高效;

比如:

依之前操作对一个业务进行定入缓存需要把数据拉取到后再定入;

而今天我们可以通过注释的方式不需要额外代码去实现对Redis的操作。

推荐在读本文之前先看一下上一篇《》

一、加入依赖

Swagger 3.0

<dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-starter-webmvc-ui</artifactId><version>2.3.0</version>
</dependency>
spring-boot-starter-cache  缓存
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-cache</artifactId>
</dependency>

二、开启缓存

@SpringBootApplication
@EnableCaching
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}

三、Swagger配置

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class SwaggerConfig {@Beanpublic GroupedOpenApi publicApi() {String[] paths = {"/**"};String[] packages = {"com.example.demo.controller"};//扫描的路径return GroupedOpenApi.builder().group("public").pathsToMatch(paths).packagesToScan(packages).build();}@Beanpublic OpenAPI openAPI() {return new OpenAPI().info(new Info().title("接口文档标题").description("SpringBoot3 集成 Swagger3接口文档").version("v1")).externalDocs(new ExternalDocumentation().description("项目API文档").url("/"));}
}

四、实体类

import lombok.Data;import java.io.Serializable;@Data
public class Stu implements  Serializable{//private static final long serialVersionUID = 1L;private Integer id;private String name;private Integer age;
}

五、服务类 注解实现

import com.example.demo.mode.Stu;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;@Service
public class RedisService {//----通过注释实现Redis的写入@Cacheable (cacheNames = "abc",unless =  "#result==null",key =  "#id")public Stu getStuById(Integer id) {Stu stu = new Stu();stu.setId(id);stu.setName("张三");stu.setAge(18);return stu;}//---- 通过注释实现Redis的更新@CachePut (cacheNames = "abc",key =  "#result.id")public Stu update(Stu stu) {stu.setName("李四");stu.setAge(19);return stu;}//---- 通过注释实现Redis的删除@CacheEvict (cacheNames = "abc",key =  "#id")public void delete(Integer id){}
}

六、控制层测试

@RestController
@Tag(name = "TestController",description = "测试接口")
@RequestMapping(value = "/swaggertest")
public class StuController {@Autowiredprivate RedisService redisService;@GetMapping("/getStuById")public Stu getStuById(Integer id){return redisService.getStuById(id);}@GetMapping("/update")public Stu update(Stu stu){return redisService.update(stu);}@DeleteMapping ("/delete")public void delete(Integer id){redisService.delete(id);}
}

七、效果展示

下篇:《Spring Boot 3.X 下Redis缓存的尝试(三):精进-用Jason进行序列化》


文章转载自:

http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://00000000.zwndt.cn
http://www.dtcms.com/wzjs/618193.html

相关文章:

  • 本地网站搭建流程做网站代码第一不
  • 毕业设计做购物网站的要求西安 内部网站建设
  • 有专业做网站dora制作网页
  • 网站建设工作小组分工如何给网站做引流
  • 网站建设规范徐州有哪些互联网公司
  • 劳务建筑公司网站织梦网站演示
  • 网站开发公司 优帮云软件开发模型有哪些
  • 杨家平网站建设如何制作企业的网站
  • 龙岩市城乡规划建设局网站无锡有人代做淘宝网站吗
  • 上海招标网站wordpress博客优化插件
  • 沈阳网站建滁州商业网站建设
  • 网站建设案例模板服装网站设计模板
  • 旅行社网站模板中国水电建设招标网站
  • 网站 技术支持中国银行全球门户网站
  • 泰安最好的网站建设公司被公司优化掉是什么意思
  • 欧洲男女做受视频网站网站建设方案书内容管理制度
  • 构建网站的步骤哪个做网站的公司好
  • 高端网站建设哪些好媒体公司网站模板
  • 广东建设执业资格中心网站管理部门网站建设说明
  • 建立网站赚钱吗网站接入变更
  • php网站开发报告书中国万网的网址是什么
  • 网站建设流程知乎软件定制开发订单
  • 长沙模板网站建设企业做网站口碑比较好的大公司
  • 旅游企业网站开发随州哪里学做网站
  • 创建全国文明城市的目的搜索引擎优化简历
  • 毫州网站建设wordpress页面缓存
  • h5响应式网站公司郑州互联网seo使用教程
  • 新手学做网站看什么书公司网页制作教程
  • 白熊阅读做网站架构国外设计网站欣赏
  • 杭州定制网站制作wordpress 3d云标签