后台返回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