后台返回model里的時間格式,用@JsonFormat是沒用的,它只有在返回JSON數據的時候生效,我腦抽了


返回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)}
效果如圖:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM