zoukankan      html  css  js  c++  java
  • springmvc 使用Jackson的配置

    <!--start:使用Jackson 1.x的配置,需要导入的jar包:jackson-core-lpgl-xxx.jar、jackson-mapper-lgpl-xxx.jar -->
    <bean class ="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
        <property name="messageConverters">
            <list>
                <!-- 设置返回字符串编码,避免使用@ResponseBody后返回乱码 -->
                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name = "supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
                <!-- json转换器 -->
                <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" >
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
    
            </list>
        </property>
    </bean>
    <!--end:使用Jackson 1.x的配置,需要导入的jar包:jackson-core-lpgl-xxx.jar、jackson-mapper-lgpl-xxx.jar -->
    复制代码

    #####################################################################################################################

    复制代码
    <!--start:使用Jackson 2.x的配置,需要导入的jar包:jackson-core-xxx.jar、jackson-annotations-xxx.jar、jackson-databind-xxx.jar-->
    <!--通过处理器映射DefaultAnnotationHandlerMapping来开启支持@Controller注解-->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
    <!--通过处理器适配器AnnotationMethodHandlerAdapter来开启支持@RequestMapping注解-->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <!-- 设置返回字符串编码 -->
                <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name = "supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                            <value>application/json;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
                <!-- json转换器 -->
                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                            <value>application/json;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>
            </list>
        </property>
    </bean>
    <!--end:使用Jackson 2.x的配置,需要导入的jar包:jackson-core-xxx.jar、jackson-annotations-xxx.jar、jackson-databind-xxx.jar-->
  • 相关阅读:
    effective C++ 条款 18:让接口容易被正确使用,不易被误用
    effective C++ 条款 24:若所有参数皆需类型转换,请为此采用nonmember函数
    PHP 归并排序
    IOS+H5页面自定义按钮无效
    vscode安装
    php 单例模式
    Warning: popen() has been disabled for security reasons in OS/Guess.php on line 241
    php 魔术方法
    php快速排序
    mysql 查询字段为空显示默认值
  • 原文地址:https://www.cnblogs.com/pureEve/p/6687816.html
Copyright © 2011-2022 走看看