用数据库函数date_format格式化下
这个得前后端规定好统一的数据格式才行
```java
/**
* 自定义类型转换器
*/
public class MyStringDataCovert implements Converter<String, Date> {
private SimpleDateFormat[] sdfs = {
new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"),
new SimpleDateFormat("yyyy-MM-dd"),
new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"),
new SimpleDateFormat("yyyy/MM/dd")
};
@Override
public Date convert(String source) {
Date date = null;
for (SimpleDateFormat sdf : sdfs) {
try {
date = sdf.parse(source);
} catch (ParseException e) {
}
}
if (date==null){
throw new RuntimeException("日期格式转换异常!");
}
return date;
}
}
然后在springMvc配置上加上这些
<mvc:annotation-driven conversion-service="MyStringDataCovert"/>
<bean id="MyStringDataCovert" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="com.java.covert.MyStringDataCovert" />
</set>
</property>
</bean>
```