When the Spring MVC return type is a string, the returned Chinese becomes "?" Processing
The Spring controller is as follows
@Controllerclass Simplecontroller { @ResponseBody @RequestMapping (value = "/hotel") publicreturn "{\" status\ ": 0,\" errmsg\ ": Null,\" data\ ": {\" query\ ": \" hotel query \ ", \" num\ ": 65544,\" url\ ": \" Www.test.com\ "}}";}}
Here using Responsebody, the return value is directly a string, no use to Jackson, if it is to return an object, using the Jackson to JSON, there is no coding problem
Then the hotel inquires a few words all become question marks
Since spring handles the result of a string type with the return value, we need to configure his encoding Stringhttpmessageconverter
class= "Java.nio.charset.Charset" factory-method= "forname" > <constructor-arg value= "UTF-8"/ > </bean> <mvc:annotation-driven> <mvc:message-converters> class= " Org.springframework.http.converter.StringHttpMessageConverter "> <constructor-arg ref=" Utf8charset "/ > </bean> </mvc:message-converters> </mvc:annotation-driven>
When the Spring MVC return type is a string, the returned Chinese becomes "?" Processing