@GetMapping(value = "findAll", produces = "text/html") @ResponseBody public String findAll(HttpServletRequest request, HttpServletResponse response, Model model) { //从redis中取html缓存 String seckillGoodsHtml = iSeckillGoodsService.getSeckillGoodsHtml(SeckillGoodsHtmlKey.seckillGoodsHtmlKey.getPrefix()); //如果不为空直接返回json if (!StringUtils.isEmpty(seckillGoodsHtml)) { return seckillGoodsHtml; } //如果redis里没有 List<SeckillGoods> seckillGoods = iSeckillGoodsService.findAll(); List<Goods> goods = iGoodsService.findAll(); model.addAttribute("SeckillGoods", seckillGoods); model.addAttribute("goods", goods); //从数据库那出来数据手动渲染模板 IWebContext webContext = new WebContext(request, response, request.getServletContext(), request.getLocale(), model.asMap()); //渲染数据模板 seckillGoodsHtml = thymeleafViewResolver.getTemplateEngine().process("seckillpage", webContext); if (!StringUtils.isEmpty(seckillGoodsHtml)) { iSeckillGoodsService.setSeckillGoodsHtml(SeckillGoodsHtmlKey.seckillGoodsHtmlKey.getPrefix(), seckillGoodsHtml); } return seckillGoodsHtml; }