spring json 返回中文乱码

如前台显示的json数据中的中文为???,则可尝试以下方法。

方法一(推荐):在@RequestMapping中添加  produces={"text/html;charset=UTF-8;","application/json;"}

@RequestMapping(value = "***",produces={"text/html;charset=UTF-8;","application/json;"})

方法二:在配置文件的 mvc:annotation-driven 中添加如下代码

<mvc:annotation-driven >
    <mvc:message-converters register-defaults="true">
      <bean class="org.springframework.http.converter.StringHttpMessageConverter">
        <property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
      </bean>
    </mvc:message-converters>
  </mvc:annotation-driven>

猜你喜欢

转载自www.cnblogs.com/yjboke/p/9274377.html
今日推荐