先來看代碼
這個對象有兩個屬性 一個是string 另一個是集合
我們再去創建一個 List<ProductProperty> ppList = new ArrayList<ProductProperty>();
pamList = productAttributeMetaService.queryByChannel("陳酒頻道");
for (int i = 0; i < pamList.size(); i++) {
ProductProperty pp = new ProductProperty();
List<String> ls = new ArrayList<String>();
String values = pamList.get(i).getValues();
String[] str = values.split(",");
for (int j = 0; j < str.length; j++) {
ls.add(str[j]);
}
pp.setKey(pamList.get(i).getProperty());
pp.setValueList(ls);
ppList.add(pp);
}
model.addAttribute("ppList", ppList); //聲明我用的是springmvc框架
<li class="clearfix">
<div class="label">${var.key }:</div>
<c:set value="${var.valueList }" var="var2"/>
<div class="filter-list more-hiden" id="">
<c:forEach items="${var2 }" var="var3">
<a href="javascript:void(0);" id="" οnclick="searchpropery(this);">${var3 }</a>
</c:forEach>
</div>
</li>
</c:forEach>
數據庫
要顯示效果
這個對象有兩個屬性 一個是string 另一個是集合
我們再去創建一個 List<ProductProperty> ppList = new ArrayList<ProductProperty>();
這樣集合lst 就是集合中嵌套集合啦。。
我們來看遍歷。。。。。。
List<ProductAttributeMetaEntity> pamList = new ArrayList<ProductAttributeMetaEntity>();pamList = productAttributeMetaService.queryByChannel("陳酒頻道");
for (int i = 0; i < pamList.size(); i++) {
ProductProperty pp = new ProductProperty();
List<String> ls = new ArrayList<String>();
String values = pamList.get(i).getValues();
String[] str = values.split(",");
for (int j = 0; j < str.length; j++) {
ls.add(str[j]);
}
pp.setKey(pamList.get(i).getProperty());
pp.setValueList(ls);
ppList.add(pp);
}
model.addAttribute("ppList", ppList); //聲明我用的是springmvc框架
前端頁面遍歷
<c:forEach items="${ppList }" var="var"><li class="clearfix">
<div class="label">${var.key }:</div>
<c:set value="${var.valueList }" var="var2"/>
<div class="filter-list more-hiden" id="">
<c:forEach items="${var2 }" var="var3">
<a href="javascript:void(0);" id="" οnclick="searchpropery(this);">${var3 }</a>
</c:forEach>
</div>
</li>
</c:forEach>
數據庫
要顯示效果