【发布时间】:2013-08-19 02:03:53
【问题描述】:
我有 2 个具有 OneToMany 关系的实体。另外,我有一个 jsp,我在其中使用 DAO 获取一些相关值,它用一个键返回我的列表。
例如:
大学
学生 a,学生 b。
我不需要在 DAO 中编写另一个方法来获取相关的学生。在大学只有一种方法,我可以从学生那里获得所有值,因为OneToMany 关系。没关系。但我想按一些东西对学生进行排序。这就是麻烦。大学实体没有学生专栏。
我怎样才能解决这个问题?我可以在 mysql 中对我的表(学生)进行排序并从已经排序的数据库中获取它吗?
这是我的jsp:
<c:forEach items="${spyList}" var="spy">
<c:forEach items="${spy.spyPath}" var="spyPath">
<table style="width: 800px; border-collapse: collapse;" width=""
align="">
<tbody>
<tr>
<td
style="width: 450px; letter-spacing: 0px; word-spacing: 0px; vertical-align: top;"><strong>
<strong> <a
href="${pageContext.request.contextPath}${spyPath.url}">${spyPath.title}</a>
</strong>
</strong><br></td>
<td style="width: 20px; letter-spacing: 0px; word-spacing: 0px;"><br></td>
<td
style="vertical-align: top; letter-spacing: 0px; word-spacing: 0px;"><div
id='date'>
<small>${spyPath.time}</small>
</div> <br></td>
</tr>
</tbody>
</table>
</c:forEach>
</c:forEach>
这是我的间谍:
@OneToMany(mappedBy = "spy")
private List<SpyPath> spyPath = new ArrayList<SpyPath>();
public List<SpyPath> getSpyPath() {
return this.spyPath;
}
public void setSpyPath(List<SpyPath> spyPath) {
this.spyPath = spyPath;
}
还有 SpyPath:
@ManyToOne
@JoinColumn(name = "ID")
private Spy spy;
public Spy getSpy() {
return this.spy;
}
public void setSpy(Spy spy) {
this.spy = spy;
}
【问题讨论】:
-
我会在客户端使用数据表进行 JSP/HTML 表排序。 datatables.net
-
您是在问如何对
List<Student>进行排序吗?阅读docs.oracle.com/javase/tutorial/collections/interfaces/… -
没有。我没有 List
。我有一键 List 。我无法排序,因为它没有理由。如何对一个值进行排序? -
你说:“但我想按一些东西对学生进行排序。这就是麻烦所在。”。那么,如果问题不是对学生列表进行排序,那么实际的问题是什么?你想达到什么目标?
-
public List<SpyPath> getSpyPath():这会返回您想要排序和显示的列表,不是吗?因此,在将其显示在 JSP 中之前对其进行排序。 docs.oracle.com/javase/tutorial/collections/interfaces/…
标签: spring hibernate jsp sorting