When the server returns Chinese, it does not use this annotation, but uses the HttpServletResponse object directly to complete the transmission, on the server side may pass Response.setcontenttype ("Text/plain;charset=utf-8 ") to set the encoding type so that there is no Chinese garbled
The return value is set according to its own data type, which is commonly used:
response.setcontenttype ("text/html; Charset=utf-8 "); HTML
response.setcontenttype ("Text/plain; Charset=utf-8 "); Text
response.setcontenttype ("Application/json; Charset=utf-8 "); Data
response.setcontenttype ("Application/xml; Charset=utf-8 "); Xml
Method Two can create a new class that implements the Beanpostprocessor
Import Java.nio.charset.Charset;
Import java.util.ArrayList;
Import java.util.List;
Import org.springframework.beans.BeansException;
Import Org.springframework.beans.factory.config.BeanPostProcessor;
Import Org.springframework.http.MediaType;
Import Org.springframework.http.converter.StringHttpMessageConverter; /** * Solve the Chinese garbled problem of @responsebody in spring MVC3 * * Public class Utf8stringbeanpostprocessor implements Beanpostprocess or {@Override public object Postprocessafterinitialization (object bean, String beanname) throws Beansexcep tion {if (bean instanceof Stringhttpmessageconverter) {MEDIATYPE mediatype = new mediatype ("TE
XT "," plain ", Charset.forname (" UTF-8 "));
list<mediatype> types = new arraylist<mediatype> ();
Types.add (mediatype);
((Stringhttpmessageconverter) bean). Setsupportedmediatypes (types);
} return bean; } @Override
public object Postprocessbeforeinitialization (object bean, String beanname) throws Beansexception {Retu
RN Bean;
}
}
Register this bean in the spring configuration file
<!--solve the use of @responsebody Chinese garbled. -->
<bean class= "Springmvc.extention.UTF8StringBeanPostProcessor" ></bean>