SpringMVC 配置Jackson方法

来源:互联网 发布:单片机应用技术实例 编辑:程序博客网 时间:2024/06/05 17:11

SpringMVC中配置Jackson的两种方法

  1. SpringMVC配置文件中配置AnnotationMethodHandlerAdapter
<bean          class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">          <property name="messageConverters">              <list>                  <!-- <bean                      class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /> 2.x中已过时 -->                      <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>                  <bean                      class="org.springframework.http.converter.StringHttpMessageConverter">                      <property name="supportedMediaTypes">                          <list>                              <value>text/plain; charset=UTF-8</value>                          </list>                      </property>                  </bean>              </list>          </property>      </bean>    

2.开启注解驱动

    <!--开启mvc注解驱动-->    <mvc:annotation-driven/>
原创粉丝点击