我在我的模型中有一个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