模塊4之使用redis實現頁面緩存


簡介

  手動渲染頁面,然后將頁面添加到redis服務器中,做成頁面緩存的功能。SpringWebContext-->thymeleafViewResolver.getTemplateEngine().process();

 1 @RequestMapping(value = "/to_list",produces = "text/html")                                                          //produces+@ResponseBody:產生特定類型的相應
 2     @ResponseBody
 3     public String goodsList(Model model, MiaoshaUser user, HttpServletRequest request, HttpServletResponse response){
 4 
 5         String html = redisService.get(GoodsPrefix.getGoodsList,"",String.class);                                  //自動渲染
 6         if (!StringUtils.isEmpty(html)){
 7             return html;
 8         }
 9 
10 
11         List<GoodsVo> goodslist = miaoshaGoodsService.getGoodsList();                                                   //手動渲染
12         model.addAttribute("goodslist",goodslist);
13         SpringWebContext ctx = new SpringWebContext(request,response,request.getServletContext(),request.getLocale(),
14                 model.asMap(),applicationContext);
15         html = thymeleafViewResolver.getTemplateEngine().process("goods_list",ctx);
16         if (!StringUtils.isEmpty(html)) {
17             redisService.set(GoodsPrefix.getGoodsList,"",html);
18         }
19         return html;
20     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM