The use of Springboot development, external development interface for call, passed in the parameters of Chinese, there is a lot of Chinese garbled, check the information, summed up the solution is as follows:
The first step, the agreed parameter encoding format
Whether using httpclient, or okhttp, to set the parameters of the encoding, in order to unify, here all set to utf-8
the second step, modify the Application.properties file
Add the following configuration:
Spring.http.encoding.force=true
spring.http.encoding.charset=utf-8
spring.http.encoding.enabled=true
Server.tomcat.uri-encoding=utf-8
The Chinese returned in the interceptor is no longer garbled, but the data returned in the controller is still garbled.
the third step, modify the controller's @requestmapping
Modify the following:
Produces= "Text/plain;charset=utf-8"
The disadvantage of this method is to limit the data type, continue to find data, find the solution on StackOverflow, is to add the following code in the configuration class:
@Configuration public class Custommvcconfiguration extends Webmvcconfigureradapter {@Bean Public httpmessageconverter<string> Responsebodyconverter () {Stringhttpmessageconverter converter = new
Stringhttpmessageconverter (Charset.forname ("UTF-8"));
return converter; } @Override public void Configuremessageconverters (list
The
can solve Springboot's Chinese garbled problem.
Ps:stackoverflow URL
http://stackoverflow.com/questions/27606769/ How-to-overwrite-stringhttpmessageconverter-default-charset-to-use-utf8-in-sprin
http://stackoverflow.com/ Questions/20935969/make-responsebody-annotated-spring-boot-mvc-controller-methods-return-utf-8