@DateTimeFormat not working properly

[亡魂溺海] 提交于 2019-12-24 02:09:45

问题


I'm having issues with using the @DateTimeFormat Spring annotation. I've been researching a bit about it today, but for some reason I just can't get it to work.

@DateTimeFormat(pattern="MM/dd/yyyy")
@Column(name="my_date")
private Date myDate;

public Date getMyDate() {
    return this.myDate;
}
public void setMyDate(Date myDate) {
    this.myDate = myDate;
}

Right now the code is displaying the date and time as yyyy-MM-dd HH:mm:ss.S (i.e. 2012-01-11 00:00:00.0)

I read that you need Joda-Time added to your class path and I've done that. Am I missing something?


回答1:


You need to enable the processing of those annotations. The easiest way is with mvc schema...

<mvc:annotation-driven />

Joda Time is not required for formatting. @DateTimeFormat can be used on long, Date and Calendar fields. If you want to use it on Joda Time fields, you need to have 1.3 or higher on your classpath



来源:https://stackoverflow.com/questions/8827122/datetimeformat-not-working-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!