我有兩個POJO的日期類型字段。 我正在使用Spring MVC並通過ModelAndView
傳遞這兩個POJO。 我可以使用compareTo()
比較控制器中的這些日期。 我想在JSP頁面中比較它們以隱藏或顯示某些td。在jsp中使用jstl比較日期對象
在控制器工作的:
for (AttendanceReport attendanceR2 : pastAttendance) {
System.out.println("For date: "+ attendanceR2.getTrainingDate());
for (Attendance attendance2 : absentCandidates) {
if (attendance2.getDateOfAbsentee().compareTo(attendanceR2.getDateOfTraining())==0) {
System.out.println("\n");
System.out.println(attendance2.getCandidate().getCandidateId() + "---- absent on--- "+ attendance2.getDateOfAbsentee());
}
}
}
我想在JSP中也是這種比較...... 沒有任何小腳本 ...!這怎麼能實現... !!
我設置從控制器的對象如下:
modelAndView.addObject("absentCandidates",absentCandidates);
modelAndView.addObject("pastAttendance",pastAttendance);
我想這是我的JSP頁面中......但它不是工作...
<c:forEach items="${pastAttendance}" var="pastAttendance">
<c:forEach items="${absentCandidates}" var="absentCandidates">
<c:if test="${pastAttendance.getDateOfTraining==absentCandidates.getDateOfAbsentee}">
<td>Some Check Box Unchecked</td>
</c:if>
</c:forEach>
</c:forEach>
dateOfTraining和dateOfAbsentee,既是類型日期的字段...他們只是沒有在JSTL中進行比較...
這兩年太遲了,但我似乎記得在JSTL中,您從get方法中刪除了最初的「get」。所以一個原因可能是因爲你應該寫:** **。 –
mwarren