我想在Spring中使用jslt打印这样的多级列表,如何编写控制器和jsp代码?
这是我的控制器代码:
@RequestMapping(value = "/index.htm", method = RequestMethod.GET)
public String loadHomePage(ModelMap map) {
List<NewsCategory> cat = newsService.getNewsCat();
for(NewsCategory c : cat){
List<News> list = newsService.getByCat(c.getId());
map.put("list-" + c.getId(), list); // is this right?
}
map.put("newscat", cat);
// And how to print these in the jsp page?
return "index";
}
谢谢!
答案 0 :(得分:0)
<c:forEach var="entry" items="${myMap}">
List name: <c:out value="${entry.key}"/>
<c:forEach items="${entry.value}" var="cat" varStatus="rowStatus">
<c:forEach items="${cat.itemList}" var="item" varStatus="rowCount">
<div>...<c:out value="${item.description}"/></div>
</c:forEach>
</c:forEach>
</c:forEach>