SpringMVC@ResponseBody返回XML文本乱码

xiaoxiao2021-02-28  46

1.测试发现返回前控制台打印都是正常无乱码,判断问题出现在spring返回时编码问题。 2.使用spring常规默认配置注解是 <mvc:annotation-driven/>这里需要添加转换器,并设置编码 <mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> <value>text/html;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>

当然spring还有其他转换器,按需添加即可

转载请注明原文地址: https://www.6miu.com/read-76389.html

最新回复(0)