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

在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>
原文地址:https://www.cnblogs.com/flying607/p/4721582.html