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

原文地址:https://www.cnblogs.com/famine/p/12463250.html