redis 缓存

1.依赖<!--缓存依赖,此处不再需要,因为他的包在其他依赖中已经有了 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artif...
摘要由CSDN通过智能技术生成

1.依赖

<!--缓存依赖,此处不再需要,因为他的包在其他依赖中已经有了
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>-->

2…注解在启动类上

@EnableCaching  //缓存

3.查询缓存
缓存的对象必须可以序列号:序列号可以使用插件generateSerilizeVersionUID生成

 @GetMapping("list")
    @Cacheable(cacheNames = "product",key = "123")  //缓存
    //@Cacheable(cacheNames = "product",key = "#id",condition=id.length()>3, unless="#result.getCode()!=0")  动态key,满足条件才缓存,unless(如果不)//缓存
   // public ResultVO list(String id){
    public ResultVO list(){
        //1.查询所有上架商品
        List<ProductInfo> productInfoList=ifoService.findUpAll();
        //2.查询所有类目(一次性查询)
        //List<Integer> categoryTypeList=new ArrayList<>();
        //传统方法
        //for (ProductInfo productInfo:productInfoList){
          //  categoryTypeList.add(productInfo.getCategoryType());
       // }
        //精简方法,Java8的lambda学习
        List<Integer> categoryTypeList=productInfoList.stream().
                map(e->e.getCategoryType()).
                collect(Collectors.toList());
        List<ProductCategory> productCategoryList=categoryService.findByCategoryTypeIn(categoryTypeList);

        //3.数据拼装
        List<ProductVO> productVOList=new ArrayList<>();
        for (ProductCategory productCategory:productCategoryList){
            ProductVO productVO=new ProductVO();
            productVO.setCategoryType(productCategory.getCategoryType());
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值