【发布时间】:2015-05-30 02:07:29
【问题描述】:
我不太擅长排序,我需要这方面的帮助
如何根据日期字段对这个 Arraylist 进行排序
控制器:
Set<CustomerAccount> cas = customer.getCustomerAccounts();
if ( !cas.isEmpty() )
{
// initialize form storage for accounts
List<AccountCustomerForm> accntForms = new ArrayList<AccountCustomerForm>( cas.size() );
AccountCustomerForm accntForm = null;
for ( CustomerAccount ca : cas )
{
// if there are more than 1 account linked to the customer's account, get all related accounts
// else only include the customer's account
if ( ca.getAccount().getCustomerAccounts().size() > 0 )
{
AccountCustomerForm jointAccountForm = null;
for ( CustomerAccount jointAccount : ca.getAccount().getCustomerAccounts() )
{
jointAccountForm = new AccountCustomerForm();
jointAccountForm.setAccountNumber( jointAccount.getAccount().getAccountNumber() );
jointAccountForm.setAccountName( jointAccount.getCustomer().getName() );
jointAccountForm.setDateOpened( jointAccount.getAccount().getDateOpened() ); //as per sir del, date opened is supposed to be seen in linked accounts -jpcbautista
jointAccountForm.setStatus( jointAccount.getAccount().getStatus() );
jointAccountForm.setJoint( jointAccount.getAccount().isJoint() );
jointAccountForm.setProductName( jointAccount.getAccount().getProductMatrix().getProductName() );
accntForms.add( jointAccountForm );
}
}
JSP:
<c:forEach items="${bean.accounts}" var="accnt" varStatus="status" begin="0">
<c:choose>
<c:when test="${status.count % 2 == 0}"><tr></c:when>
<c:otherwise><tr bgcolor="#BFDFFF"></c:otherwise>
</c:choose>
<td>${accnt.accountNumber}</td>
<td>${accnt.accountName}</td>
<td>
${accnt.dateOpened}</td>
<td>${accnt.status}</td>
<c:choose>
<c:when test = "${accnt.joint}" > <td> Yes </td> </c:when>
<c:otherwise> <td> No</td></c:otherwise>
</c:choose>
<td>${accnt.productName}</td>
<td></td>
<!-- <td></td> -->
</c:forEach>
我想知道如何使用“打开日期”字段对这些数据进行排序。提前致谢。
【问题讨论】:
-
您可以使用
Collections.sort进行排序。只需提供您自己的Comparator。
标签: java javascript jsp sorting arraylist