标签:接口 ring servlet accept handle sage ada charset port
在springmvc.xml中加入下面一段
<mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <!-- 用于避免响应头过大 --> <property name="writeAcceptCharset" value="false"/> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> <value>text/html;charset=UTF-8</value> </list> </property> </bean> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/json;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>
如果只是解决中文乱码问题只要加入下面一段
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> </list> </property> </bean> </list> </property> </bean>
springmvc 接口返回类转为json,并处理中文乱码问题
标签:接口 ring servlet accept handle sage ada charset port
原文地址:https://www.cnblogs.com/blackl/p/10579934.html