JavaWeb——redis【综合案例】使用redis缓存商品分类
思路分析:
![0a2ee3c82432e4724e2af71463b0431e.png](https://i-blog.csdnimg.cn/blog_migrate/89e7817df411d9763543cbc9e03812b5.jpeg)
- 查询redis,没有json数据,就调用CategoryDao,去获取集合
List<Category>
先返回给CategorySrvice,再转成json存进redis - 第二次起,直接获取redis中的json,将json转成
List<Category>
我这边使用测试驱动开发,所以,我先写一个测试类,目的是明确需求:
CategoryServiceTest类
package com.lbl.service;
import com.lbl.bean.Category;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
public class CategoryServiceTest {
@Test
public void test01() throws IOException {
//1.创建服务类对象
CategoryService categoryService = new CategoryService();
//2.查询分类集合
List<Category> list=categoryService.findAll();
//打印出结果
for (Category c:list){
System.out.println(c);
}
}
}
CategoryService
package com.lbl.service;
import com.lbl.bean.C