zoukankan      html  css  js  c++  java
  • 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>

       

  • 相关阅读:
    Shell中的特殊变量和结构
    自由的Debian
    关于系统定制的一些链接
    超出两行显示省略号
    json转换
    区分LocalStorage和偏好数据
    去除谷歌浏览器中的默认文本框样式
    js访问xml
    js执行跨域请求
    mvc通过controller创建交互接口
  • 原文地址:https://www.cnblogs.com/duwenlei/p/4825368.html
Copyright © 2011-2022 走看看