SpringMVC 使用@ResponseBody返回json 中文乱码

来源:互联网 发布:deepin 删除软件 编辑:程序博客网 时间:2024/05/21 19:44

方法一,使用(produces = "application/json; charset=utf-8"):

    @RequestMapping(value="/getUsersByPage",produces = "application/json; charset=utf-8")//    @RequestMapping("/getUsersByPage")    @ResponseBody    public String getUsersByPage(String page,String rows,String text,HttpServletRequest request,HttpServletResponse response){

方法二,在spring-mvc.xml中添加:

<!-- 处理请求返回json字符串的中文乱码问题 -->
    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

原创粉丝点击