springmvc 返回json数据时日期类型格式化 jsonDate
程序员文章站
2022-04-30 11:29:45
...
在spring-mvc.xml中配置如下即可(通用配置方法): <mvc:annotation-driven> <mvc:message-converters> <bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> <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>
特殊格式化方式请参考:http://www.cnblogs.com/woshimrf/p/5189435.html