0
点赞
收藏
分享

微信扫一扫

JAVA中文注解驱动,解决api接口返回的json里面出现中文乱码的问题

AbrahamW 2022-12-22 阅读 63


 

 

在src/main/resources/springmvc-servlet.xml中加入

<!-- 中文注解驱动 -->
<mvc:annotation-driven><!-- 指定http返回编码格式,不然返回Ajax请求json会出现中文乱码 -->
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
<value>*/*;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

举报

相关推荐

0 条评论