Date
实现 Convert 接口
public class StringToDate implements Convert<String,Date>{
public Date convert(String source){
if(source == null){
throw new RuntimeException("请您输入数据");
}
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try{
return df.parse(source );
}catch(Exception e){
throw new RuntimeException("请您输入数据");
}
}
}
springmvc.xml
<!--配置自定义类型转换器-->
<bean id = "XXX" class = "XXXXX.ConversionServicinvertersceFactoryBean">
<property name="converts">
<set>
<bean class="com.leavescai.utils.StringToDate"/> //自定义转换器得全路径
</set>
</property>
</bean>
springmvc.xml
<!-- 开启扫描 -->
<mvc:annotation-driven conversion-service="conversionService"/>
原文:https://www.cnblogs.com/LeavesCai7/p/14084113.html