Spring Boot Chinese garbled solution

Source: Internet
Author: User


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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.