zoukankan      html  css  js  c++  java
  • 模块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     }
  • 相关阅读:
    053467
    053466
    053465
    NC201613 Jelly
    NC14608 after与迷宫
    NC14572 走出迷宫
    340. 通信线路
    1135. 新年好
    903. 昂贵的聘礼
    P5767 [NOI1997]最优乘车
  • 原文地址:https://www.cnblogs.com/deijiawoyu/p/12690913.html
Copyright © 2011-2022 走看看