<mvc:annotation-driven conversion-service="conversionService"/>
<bean id="conversionService"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<list>
<!-- <bean class="com.ll.model.StringToPersonConverter" /> -->
</list>
</property>
</bean>
1、後臺日期類型解析到前端html
1.在springmvc的配置文件中添加這個.annotation-driven在配置文件中只配置一次 (此方法全局做用)
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss"/>
</bean>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>前端
2.直接在字段上寫上
@JsonFormat(pattern="yyyy-MM-dd",timezone="GMT-8")
private Date inputtime;java
2、前端日期類型傳到後臺spring
1.在Controller類中添加這個方法 (此方法全局做用)
@InitBinder
public void initBinder(WebDataBinder binder){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}json
2.直接在字段上添加
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date beginDate;mvc
第三種:https://blog.csdn.net/u012410733/article/details/72773095app