1.自定义注解转换
首先实现Convert<Object1,Object2>接口,其中Object1是现有的类型,Object2是要转换的类型。
然后是配置spring的xml。配置转换对应的Bean org.springframework.context.support.ConversionServiceFactoryBean
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<ref bean="myConverter"></ref>
</set>
</property>
开启静态资源的annotation-driven配置上转换
<mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>
conversion-service对应的是ConversionServiceFactoryBean对应的id
2.数据格式化
Spring 提供了两个可以用于格式化数字、日期和时间的注解@NumberFormat和@DateTimeFormat,这两个标签可以用于javabean的属性或方法参数上。
注册的bean设置为org.springfra