Because in the RestTemplate class, the constructor RestTemplate ()
This. messageConverters. add (new StringHttpMessageConverter ());
The StringHttpMessageConverter class in this sentence, the default is the ISO-8859-1:
Public static final Charset DEFAULT_CHARSET = Charset. forName ("ISO-8859-1 ");
Solution:
In the source code of the StringHttpMessageConverter class
Charset. forName ("ISO-8859-1 ");
Change
Charset. forName ("UTF-8 ");
Compile and re-place it in org. springframework. web-3.0.5.RELEASE.jar.
There is another way to write in your sping-servlet.xml using the configuration method:
'<Bean class = "org. springframework. web. servlet. mvc. annotation. AnnotationMethodHandlerAdapter">
<Property name = "messageConverters">
<List>
<Bean class = "org. springframework. http. converter. StringHttpMessageConverter">
<Property name = "supportedMediaTypes">
<List>
<Value> text/html; charset = UTF-8 </value>
</List>
</Property>
</Bean>
</List>
</Property>
</Bean>
In this way, the server-side spring encoding method is UTF-8.