pom.xml的配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.11</version>
</dependency>
配置文件 application.yml
spring:
redis:
database: 13
host: 127.0.0.1
port: 6379
jedis:
pool:
max-active: 100
max-idle: 100
min-idle: 10
max-wait: 1000ms
controller
@GetMapping("/gpage")
public ModelAndView showGoods(Long goodsId){
ModelAndView mav = new ModelAndView("/goods");
logger.info(“goodsId—>>>”+goodsId);
Goods goods = goodsService.findById(goodsId);
List<GoodsCover> covers = goodsCoverService.findByGoodsId(goodsId);
List<GoodsParam> params = goodsParamService.findByGoodsId(goodsId);
List<GoodsDetail> details = goodsDetailService.findByGoodsId(goodsId);
mav.addObject("goods",goods);
mav.addObject("covers", covers);
mav.addObject("details", details);
mav.addObject("params", params);
return mav;
}
在service中使用redis缓存
@Cacheable(value=“goods” , key = “#goodsId”)
public Goods findById(Long goodsId){
return goodsDao.findById(goodsId);
}