Mainly, the matching string is found in the string returned by Spring mvc parsing. The StringHttpMessageConverter class parses the string, which is used by default.
public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");
Solution:
1. Add produces = "application/json; charset=utf-8" to the method that needs to return a string. For a single method
such as :
@RequestMapping(value = "/getInfos", produces="application/json;charset=UTF-8") @ResponseBody public String getInfos(@RequestBody String request) { return "Chinese"; }
2. Configure the interceptor in the spring mvc configuration file
<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>