spring mvc4处理日期格式问题

来源:互联网 发布:yaml nginx 编辑:程序博客网 时间:2024/05/29 15:04
<!-- 注解驱动 -->
<mvc:annotation-driven validator="validator">
<mvc:message-converters>
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<!--避免IE执行AJAX时,返回JSON出现下载文件 -->
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>text/json;charset=UTF-8</value>
<!-- <value>application/json;charset=UTF-8</value> -->
</list>
</property>
<!-- 处理responseBody里面日期类型,将其中的日期设置为指定的日期格式 -->
<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>
<!--自定义json格式application/crypt-json -->
<bean id="cryptFastJsonHttpMessageConverter"
class="com.ybdc.yy.base.basis.utils.converter.CryptFastJsonHttpMessageConverter">
<property name="returnKeyName" value="key"></property>
<property name="supportedMediaTypes">
<list>
<value>application/crypt-json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>

</mvc:annotation-driven>


特殊日期格式配制使用(@JsonFormat)在对应实体类的get方法上,如下:

@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") public Date getBirth() {      return birth; }

 



0 0
原创粉丝点击