Custom converter implementation Converter Interface
//String It's the original type ,Date Is the target type to convert public class CustomDateConverter implements
Converter<String, Date> { @Override public Date convert(String source) { try {
return new SimpleDateFormat("yyyy-MM-dd").parse(source); } catch (Exception e)
{ e.printStackTrace(); } return null; } }
Configuration converter

Configuration mode 1 : For not using mvc Driven
<!-- Annotation adapter --> <bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="webBindingInitializer" ref="customBinder"></property> </bean>
<!-- custom webBinder --> <bean id="customBinder"
class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="conversionService" ref="conversionService" /> </bean> <!--
conversionService --> <bean id="conversionService"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<!-- converter --> <property name="converters"> <list> <bean
class="cn.itcast.ssm.controller.converter.CustomDateConverter"/> </list>
</property> </bean>
Configuration mode 2 : For use mvc Driven
<mvc:annotation-driven conversion-service="conversionService">
</mvc:annotation-driven> <!-- conversionService --> <bean
id="conversionService"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<!-- converter --> <property name="converters"> <list> <bean
class="cn.itcast.ssm.controller.converter.CustomDateConverter"/> </list>
</property> </bean>
 

Technology