Date 如何在Spring3MVC中允许空日期
我已经为日期绑定定义了一个全局格式化程序:Date 如何在Spring3MVC中允许空日期,date,spring-mvc,formatter,Date,Spring Mvc,Formatter,我已经为日期绑定定义了一个全局格式化程序: <annotation-driven conversion-service="conversionService" /> <beans:bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <beans:property name="con
<annotation-driven conversion-service="conversionService" />
<beans:bean id="conversionService"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<beans:property name="converters">
<beans:list>
...
</beans:list>
</beans:property>
<beans:property name="formatters">
<beans:set>
<beans:bean id="dateFormatter"
class="org.springframework.format.datetime.DateFormatter">
<beans:constructor-arg><beans:value>dd/MM/yyyy</beans:value></beans:constructor-arg>
</beans:bean>
</beans:set>
</beans:property>
</beans:bean>
...
年月日
这是工作良好,但现在我还需要一个特定的日期字段可以留空。如何配置格式化程序(或此字段)以接受空值
谢谢!:) 您可以通过在false中为DateFormatter设置lenient来完成此操作
<mvc:annotation-driven conversion-service="conversionService"/>
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="formatters">
<set>
<bean class="org.springframework.format.datetime.DateFormatter">
<constructor-arg>
<value>dd/MM/yyyy</value>
</constructor-arg>
<property name="lenient" value="false"/>
</bean>
</set>
</property>
</bean>
年月日
您可以通过在false中为DateFormatter设置lenient来完成此操作
<mvc:annotation-driven conversion-service="conversionService"/>
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="formatters">
<set>
<bean class="org.springframework.format.datetime.DateFormatter">
<constructor-arg>
<value>dd/MM/yyyy</value>
</constructor-arg>
<property name="lenient" value="false"/>
</bean>
</set>
</property>
</bean>
年月日