Search in sources :

Example 11 with TbItem

use of cn.e3mall.manager.pojo.TbItem in project e3mall by colg-cloud.

the class HtmlGenListener method onMessage.

@Override
public void onMessage(Message message) {
    try {
        // 创建一个模版
        // 从消息中取商品id
        TextMessage textMessage = (TextMessage) message;
        String text = textMessage.getText();
        Long itemId = Long.parseLong(text);
        // 等待事务提交
        Thread.sleep(1000);
        // 根据商品id查询商品信息,商品基本信息和商品描述
        TbItem tbItem = tbItemService.getTbItemById(itemId);
        TbItemDto tbItemDto = new TbItemDto(tbItem);
        TbItemDesc tbItemDesc = tbItemDescService.findById(itemId);
        // 创建一个数据集,把商品数据封装
        Map<String, Object> map = new HashMap<>();
        map.put("item", tbItemDto);
        map.put("itemDesc", tbItemDesc);
        // 加载模版对象
        Configuration configuration = freeMarkerConfig.getConfiguration();
        Template template = configuration.getTemplate("item.ftl");
        // 创建一个输出流,指定输出的目录及文件名
        Writer out = new FileWriter(HTML_GEN_PATH + itemId + ".html");
        // 生成静态页面
        template.process(map, out);
    } catch (JMSException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (TemplateException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) FileWriter(java.io.FileWriter) JMSException(javax.jms.JMSException) IOException(java.io.IOException) Template(freemarker.template.Template) TbItemDto(cn.e3mal.item.vo.TbItemDto) TbItemDesc(cn.e3mall.manager.pojo.TbItemDesc) TextMessage(javax.jms.TextMessage) TbItem(cn.e3mall.manager.pojo.TbItem) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

TbItem (cn.e3mall.manager.pojo.TbItem)11 TbUser (cn.e3mall.manager.pojo.TbUser)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 TbItemDesc (cn.e3mall.manager.pojo.TbItemDesc)3 JMSException (javax.jms.JMSException)3 TbItemDto (cn.e3mal.item.vo.TbItemDto)2 TextMessage (javax.jms.TextMessage)2 TbItemMapper (cn.e3mall.manager.dao.TbItemMapper)1 PageInfo (com.github.pagehelper.PageInfo)1 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Message (javax.jms.Message)1 Session (javax.jms.Session)1 Test (org.junit.Test)1