The default processing string encoded as iso-8859-1 for spring MVC, which causes garbled characters, For specific reference, public static final Charset Default_charset in the Org.springframework.http.converter.StringHttpMessageConverter class = Charset.forname ("iso-8859-1");
Workaround:
The first method:
Add annotations for methods that need to return a string, as follows:
@RequestMapping (value= "/getusers", produces = "application/json; Charset=utf-8 ")
Public String Getalluser () throws Jsongenerationexception, Jsonmappingexception, IOException
{
list<user> users = Userservice.getall ();
Objectmapper om = new Objectmapper ();
System.out.println (om.writevalueasstring (users));
DataGrid dg = new DataGrid ();
Dg.setdata (users);
Return om.writevalueasstring (DG);
}
This method works only for a single invocation method.
The second method:
In the configuration file, add
<mvc:annotation-driven>
<mvc:message-converters register-defaults= "true" >
<bean class= "Org.springframework.http.converter.StringHttpMessageConverter" >
<property name= "supportedmediatypes" value = "Text/plain;charset=utf-8"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
Reference: Http://stackoverflow.com/questions/3616359/who-sets-response-content-type-in-spring-mvc-responsebody
Solve spring MVC @ResponseBody return Chinese string garbled problem