我在我的模型中有一個Joda-DateTime字段,並且想要在JSP視圖中顯示它的格式。如何在Spring MVC 3.0中顯示格式化的DateTime?
public class Customer {
private DateTime dateOfBirth;
@DateTimeFormat(style="M-")
public DateTime getDateOfBirth() {
return dateOfBirth;
}
}
現在,我想在我的JSP來顯示出生日期:我已經與新@DateTimeFormat註解它
Date of birth: ${customer.dateOfBirth}
但結果是未格式化:
Date of birth: 2010-08-11T11:23:30.148+02:00
後一些研究發現,我必須使用彈簧:bind-tag:
<spring:bind path="customer.dateOfBirth">
Date of birth: ${status.value}
</spring:bind>
有了它,它的作品。但這個簡單的任務似乎太複雜了。在列表中使用這種方法會更復雜,因爲您必須將列表索引集成到綁定路徑中。
所以我的問題是:是否有一種更簡單的方式來顯示格式化值使用彈簧格式化註釋?
Spring:eval很棒。除此之外我還提出了在JSP中集成SpEL的增強要求。謝謝。 – 2010-08-11 20:38:58
我發現spring的一個小問題:版本3.0.3中的eval。當表達式求值爲null時,打印字符串'null'。相反,我的問題中的spring:bind示例在表達式計算爲null時打印一個空字符串。有沒有辦法來抑制'null'的輸出?謝謝。 – 2010-08-11 21:43:11
你可以在http://jira.springframework.org上打開JIRA來報告這個問題嗎? – kdonald 2010-08-11 22:54:35