zoukankan      html  css  js  c++  java
  • e3mall_day10

    1网页静态化方案

       》网页最好预先生成好

     2.改造jsp成freemarker

    3.MessageListener实现

      》在item-web实现对商品添加的监听器,用于同步或生成静态页面

      》写入核心依赖,springmvc配置activemq相关的对象

      》书写代码:

    public class ItemAddMessageListener implements MessageListener{
    
        @Autowired
        private ItemService itemService;
        
        @Autowired
        private FreeMarkerConfigurer configurer;
        
        public void onMessage(Message message) {
            
            //1.创建模板文件(手动创建)
            
            try {
                //2.获取商品id
                TextMessage textMessage = (TextMessage) message;
                String str_id = textMessage.getText();
                Long itemId = new Long(str_id);
                
                //3.查询商品
                TbItem tbItem = itemService.getItemById(itemId);
                Item item = new Item(tbItem);
                
                //4.查询商品描述
                TbItemDesc itemDesc = itemService.getItemDescById(itemId);
                
                //5.创建map,添加数据集到map
                HashMap<String, Object> map = new HashMap<String,Object>();
                
                map.put("item", item);
                map.put("itemDesc", itemDesc);
                
                //6.创建流
                FileWriter writer = new FileWriter( new File("D:/tmp/"+itemId+".html") );
                
                //7.加载指定的模板文件,生成模板对象
                Configuration configuration = configurer.getConfiguration();
                Template template = configuration.getTemplate("index.ftl");
                
                //8.生成文件
                template.process(map, writer);
                
                //9.关闭流
                writer.close();
                
            } catch (Exception e) {
                e.printStackTrace();
            }
            
        }
    
    }

    4.nginx访问静态页面

  • 相关阅读:
    bzoj3280
    bzoj3876
    洛谷 p1625
    bzoj1407
    bzoj1227
    bzoj1477 && exgcd学习笔记
    bzoj1345
    c#程序的config文件问题
    思维角度的重要性
    python异步初步窥探
  • 原文地址:https://www.cnblogs.com/ibcdwx/p/13553279.html
Copyright © 2011-2022 走看看