SpringMVC 使用@ResponseBody返回json 中文亂碼

藍星花發表於2017-12-14

方法一,使用(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>

相關文章