freemarker循环获取list中map的值

1.数据结构

List> mapList = Lists.newArrayList();
Long originalOrderId = returnObj.getOriginalOrderId();
List orderIdList = Lists.newArrayList();
orderIdList.add(originalOrderId);
List itemList = itemService.listByOrderIdList(orderIdList);
for (Item item : itemList) {
	
	Map map = Maps.newLinkedHashMap();
	if(item != null){
		Product product = item.getProduct();
		if(product == null){
			product = productService.get(item.getProductId());
		}
		if(product != null){
			map.put("productName", product.getName());
		}
		List specList = item.getSpecItemList();
		if(CollectionUtils.isEmpty(specList)){
			specList = JSON.parseArray(item.getSpecJson(), SpecJsonItem.class);
		}
		if(CollectionUtils.isNotEmpty(specList)){
			StringBuffer spec = new StringBuffer();
			for (SpecJsonItem specJsonItem : specList) {
				spec.append(specJsonItem.getName()).append(":").append(specJsonItem.getValue()).append(" ");
			}
			map.put("spec", spec);
		}
	}else{
		item = new Item();
	}
	map.put("item", item);
	mapList.add(map);
}

model.addAttribute("mapList", mapList);
2.前端页面循环

<#list mapList as map>
	
		商品名称:
		${map['productName']}
		商品图片:
		
	
	
	
		购买规格:
		${map['spec']}
	
	
	
		购买价格:
		${map['item'].price}
		购买数量:
		${map['item'].quantity}
	



你可能感兴趣的:(Freemarker)