Search in sources :

Example 1 with TbItemDto

use of cn.e3mal.item.vo.TbItemDto in project e3mall by colg-cloud.

the class TbItemController method showItemInfo.

/**
 * 根据商品id获取商品详情并返回页面
 */
@GetMapping("/{itemId}")
public String showItemInfo(@PathVariable Long itemId, Model model) {
    // 调用服务取商品基本信息
    TbItem tbItem = tbItemService.getTbItemById(itemId);
    // 把TbItem转换成Item对象
    // BeanUtils.copyProperties(tbItem, tbItemDto);// 性能较慢
    TbItemDto tbItemDto = new TbItemDto(tbItem);
    // 取商品描述信息
    TbItemDesc tbItemDesc = tbItemDescService.findById(itemId);
    // 把信息传递给页面
    model.addAttribute("item", tbItemDto);
    model.addAttribute("itemDesc", tbItemDesc);
    // 返回逻辑视图
    return "item";
}
Also used : TbItemDto(cn.e3mal.item.vo.TbItemDto) TbItemDesc(cn.e3mall.manager.pojo.TbItemDesc) TbItem(cn.e3mall.manager.pojo.TbItem) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with TbItemDto

use of cn.e3mal.item.vo.TbItemDto 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

TbItemDto (cn.e3mal.item.vo.TbItemDto)2 TbItem (cn.e3mall.manager.pojo.TbItem)2 TbItemDesc (cn.e3mall.manager.pojo.TbItemDesc)2 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 HashMap (java.util.HashMap)1 JMSException (javax.jms.JMSException)1 TextMessage (javax.jms.TextMessage)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1