@Autowired
private TbItemMapper itemMapper;
@Override
public boolean genItemHtml(Long goodsId){
try {
Configuration configuration = freeMarkerConfig.getConfiguration(); Template template = configuration.getTemplate("item.ftl");
Map dataModel=new HashMap<>();
//1.加载商品表数据
//2.加载商品扩展表数据
//3.商品分类
//4.SKU 列表
TbItemExample example=new TbItemExample(); Criteria criteria = example.createCriteria();
criteria.andStatusEqualTo("1");//状态为有效
criteria.andGoodsIdEqualTo(goodsId);//指定 SPU ID
example.setOrderByClause("is_default desc");//按照状态降序,保证第一个为默
认
List<TbItem> itemList = itemMapper.selectByExample(example); dataModel.put("itemList", itemList);
Writer out=new FileWriter(pagedir+goodsId+".html"); template.process(dataModel, out);
out.close();
return true;
} catch (Exception e) { e.printStackTrace(); return false;
}
}
<script>
//SKU 商品列表
var skuList=[
<#list itemList as item>
{
"id":${item.id?c}, "title":"${item.title!''}",
"price":${item.price?c},
"spec": ${item.spec}
} ,
</#list>
];
</script>
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |