SpEL可以为bean属性使用特殊的日期格式吗?

时间:2013-11-02 14:10:46

标签: date javabeans date-format spring-3 spring-el

我有一个名为birthday的日期属性的bean:

<property name="birthday" value="06/12/1980"/>

我可以指定我的bean的日期格式,以便获得12月6日或6月12日,或者是一直使用的默认格式吗?

1 个答案:

答案 0 :(得分:1)

有选项:

  • 在bean中注入日期和格式以返回所需的字符串表示。
  • 使用Formatter SPI并配置开箱即用的DateFormatter实例。这是Javadoc
  • 实施并注册您自己的Formatter实例,然后将其传递给@Formatted注释。或者使用其他注释来处理更多特殊情况。这被描述为here