zoukankan      html  css  js  c++  java
  • SpringMVC 控制器@ResponseBody返回JSON乱码问题

    Spring4的版本,在mvc配置文件中<mvc:annotation-driven />位置前增加配置:

    <!-- 用于使用@ResponseBody后返回中文避免乱码 --> 
         <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" >  
            <property name="messageConverters">  
                <list>  
                    <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>  
                                <value>text/html;charset=UTF-8</value>  
                            </list>  
                        </property>  
                    </bean>  
                </list>  
            </property>  
        </bean> 

    Spring3的版本,<mvc:annotation-driven >标签需要增加以下配置:

    <!-- SpringMVC注解驱动 -->  
    <mvc:annotation-driven>  
        <mvc:message-converters>  
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>  
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">  
                <property name="supportedMediaTypes">  
                    <list>  
                        <value>text/plain;charset=utf-8</value>  
                        <value>text/html;charset=UTF-8</value>  
                    </list>  
                </property>  
            </bean>  
        </mvc:message-converters>  
    </mvc:annotation-driven> 
  • 相关阅读:
    使用VS Code插件Graphviz Preview来画图
    Y1S002 xshell脚本编写示意
    Y1S001 ubuntu下samba安装配置以及使用vbs映射到驱动器
    Y1吐槽002 情绪
    Y1E001 HDI二阶板、三阶板
    Y1O001波分复用器
    2018-4-5-cadence skill
    2018-4-5-MEMS
    2018-4-5-硬件集成测试规程结构
    Cadence学习笔记
  • 原文地址:https://www.cnblogs.com/zealon/p/6762149.html
Copyright © 2011-2022 走看看