您的位置:首页 > 编程语言 > Java开发

springMVC 【@response 返回对象自动变成json并且防止乱码】 & 【配置支持实体类中的@DateTimeFormat注解】

2015-08-11 17:12 579 查看
在springmvc的配置文件中加上这一段即可

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<!-- 本文关键内容-->
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" >
<property name="supportedMediaTypes">
<value>text/html;charset=UTF-8</value>
</property>
</bean>
</list>
</property>

<!-- 支持@DateTimeFormat(pattern="yyyy-MM-dd")等注解  2015年7月31日11:07:03 liuyx-->
<property name="webBindingInitializer">
<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="conversionService">
<bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean"></bean>
</property>
</bean>
</property>
</bean>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: