【发布时间】:2013-12-06 18:59:00
【问题描述】:
我需要从数据库中检索项目并以特定顺序在浏览器上显示它们。
我有两个 forEach 循环,第一个循环遍历工厂对象的产品,第二个循环遍历每个产品的不同类型。
我需要根据每种产品的价格显示排序结果,但每次刷新页面时使用以下代码,结果将以不同的顺序显示。
我需要对结果进行排序,不管是在使用 Hibernate 检索它们时还是在浏览器上显示时排序。
<c:forEach var="product" items="${factory.products}">
<table border="2">
<thead><tr><td>ID</td><td>Type</td><td>Amount</td></tr></thead>
<tbody>
<c:forEach var="ptype" items="${product.types}">
<tr>
<td>${ptype.id}</td>
<td>${ptype.name}</td>
<td>${ptype.price}</td>
</tr>
</c:forEach>
</tbody>
</table>
<hr/>
</c:forEach>
我正在检索结果如下
Factory factory = (Factory) session.createCriteria(factory.class, "fac")
.createAlias("fac.products", "pro")
.createAlias("pro.types", "types")
.setFetchMode("pro", FetchMode.SELECT)
.add(Restrictions.eq("fac.id", facId))
.addOrder(Property.forName("types.price").asc())
.list().get(0);
【问题讨论】:
标签: hibernate jsp sorting struts2 jstl