spring webmvc使用ResponseBody前,在配置文件中的配置

spring的版本不同, 导致配置引用地址不同 

首先引用一个jar包

  

<dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.5.2</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.2</version>
        </dependency>

 

 一. 当前spring版本3.x

  

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
        <property name="messageConverters">  
            <list>  
                <ref bean="jsonHttpMessageConverter" />  
            </list>  
        </property>  
    </bean>  
      
    <bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
                <value>application/json;charset=UTF-8</value>  
            </list>  
        </property>  
    </bean>

  二.当前spring版本4.x

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
        <property name="messageConverters">  
            <list>  
                <ref bean="jsonHttpMessageConverter" />  
            </list>  
        </property>  
    </bean>  
      
    <bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
                <value>application/json;charset=UTF-8</value>  
            </list>  
        </property>  
    </bean>

   

posted @ 2015-09-21 10:19  哎呦喂,我的小祖宗╰つ  阅读(596)  评论(0编辑  收藏  举报