spring中的类型转换
类型转换
spring提供了供在用户自定义的扩展机制
具体步骤:
第一步:编写自己的类 继承自spring的PropertyEditorSupport类public class UtilDatePropertyEditor extends PropertyEditorSupport { private String format = "yyyy-MM-dd"; public void setAsText(String dateText) throws IllegalArgumentException { SimpleDateFormat sdf = new SimpleDateFormat(format) ; Date date = null ; date = sdf.parse(dateText) ; this.setValue(date) ; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; }第二步:配置
<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer" > <property name="customEditors"> <map> <entry key="java.util.Date" > <bean class="com.cs.dao.UtilDatePropertyEditor"> <property name="format" value="yyyy-MM-dd" /> </bean> </entry> </map> </property> </bean> <!-- <bean id="utilDatePropertyEditor" class="com.cs.dao.UtilDatePropertyEditor" /> -->注意:customEditorConfigurer 是给spring内部用的 , spring内部是根据类来查找的,所以这里的id并没有实际意义
如果要加入多个,值需往map里中加入<entry>即可
相关推荐
yupi0 2020-10-10
spring 2020-08-18
编程点滴 2020-07-29
幸运小侯子 2020-07-05
itjavashuai 2020-07-04
qingjiuquan 2020-06-29
shushan 2020-06-25
小鱿鱼 2020-06-22
咻pur慢 2020-06-18
melonjj 2020-06-17
qingjiuquan 2020-06-13
neweastsun 2020-06-05
小鱿鱼 2020-06-05
mxcsdn 2020-05-31
吾日五省我身 2020-05-27
牧场SZShepherd 2020-05-27
sweetgirl0 2020-05-14