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访问静态页面

  • 相关阅读:
    CRF++条件随机场
    list 函数
    转:Java Map 排序定义
    C#统计文本单词个数2
    转:求多边形的面积 算法几何
    C#统计单词词频
    C#动态数组ArrayList
    转:java写一个方法实现统计一条英文语句忠每个单词的个数
    C#统计文本单词的个数
    统计文本单词个数,并个数大小按序排列 C#
  • 原文地址:https://www.cnblogs.com/ibcdwx/p/13553279.html
Copyright © 2011-2022 走看看