使用@ResponseBody返回json中文乱码|springmvc|疯狂学java

更多java视频教程和java学习路线
疯狂学java官方网址:http://www.learnm.cn
方法一:使用(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中添加:

<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>

猜你喜欢

转载自blog.csdn.net/qq_21142893/article/details/85492469