返回model的數據,可以這樣做:
在實體類里添加一個格式時間的方法:
public String formateTime(Date date) {
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
return df.format(date);
}
然后在頁面中使用:
<tr th:each="course:${courseList}">
<td scope="row" th:text="${course.id}">id</td>
<td th:text="${course.name}">空空如也</td>
<td th:text="${course.formateTime(course.startTime)}">startTime</td>
<td th:text="${course.formateTime(course.endTime)}">endTime</td>
</tr>
如上course.formateTime(course.startTime)}
效果如圖: