看了网上的帖子说在自己的资源文件里写自定义错误信息,如:
typeMismatch.java.util.Date=xxxxxx
我已经在Spring的配置里把这个资源文件加载了
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>message</value>
</list>
</property>
</bean>
而且在jsp页面上可以输出里面的错误信息:
<spring:message code="typeMismatch.java.util.Date"/>
但是在调用Controller进行数据绑定的时候,如果发生类型转换错误,错误信息还是默认的那个一大串
Field error in object 'user' on field 'birthDay': rejected value [ccc]; codes [typeMismatch.user.birthDay,typeMismatch.birthDay,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.birthDay,birthDay]; arguments []; default message [birthDay]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'birthDay'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "ccc"]
.....
在里面看到了
codes [typeMismatch.user.birthDay,typeMismatch.birthDay,typeMismatch.java.util.Date,typeMismatch];
我把这几个key都加到message.properties了,可就是不起作用。
到底是怎么回事呢?
--
FROM 210.82.55.*