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());