The Spring Boot controller code is as follows:
After the browser accesses the controller, I find that Chinese is displayed as ?? Question marks, letters and numbers are displayed normally, and through network requests, the request headers can be found as follows:
Solution:
1: Modify the application.properties file
2: Create an internationalized support configuration class (If it is not configured correctly, please see the configuration at the end of the article)
Restart the project, re-access the controller, and find that the Chinese characters are displayed normally, as follows:
However, the Accept-Charset in the response header has a lot more data, as follows:
Accept-Charset: adobe-standard-encoding, big5, big5-hkscs, bocu-1, cesu-8, cp1363, cp851, euc-jp, euc-kr, gb18030, gb2312, gb_2312-80, gbk, hp-roman8, hz-gb-2312, ibm-thai, ibm00858, ibm01140, ibm01141, ibm01142, ibm01143, ibm01144, ibm01145, ibm01146, ibm01147, ibm01148, ibm01149, ibm037, ibm1026, ibm1047, ibm273, ibm277, ibm278, ibm280, ibm284, ibm285, ibm290, ibm297, ibm420, ibm424, ibm437, ibm500, ibm775, ibm850, ibm852, ibm855, ibm857, ibm860, ibm861, ibm862, ibm863, ibm864, ibm865, ibm866, ibm868, ibm869, ibm870, ibm871, ibm918, iso-2022-cn, iso-2022-cn-ext, iso-2022-jp, iso-2022-jp-1, iso-2022-jp-2, iso-2022-kr, iso-8859-1, iso-8859-10, iso-8859-13, iso-8859-14, iso-8859-15, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-9, jis_x0201, jis_x0212-1990, koi8-r, koi8-u, ksc_5601, macintosh, scsu, shift_jis, tis-620, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-32be, utf-32le, utf-7, utf-8, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, windows-31j, x-big5-hkscs-2001, x-big5-solaris, x-compound-text, x-ebcdic-xml-us, x-euc-jp-linux, x-euc-tw, x-euc-tw-2014, x-eucjp-open, x-gsm-03.38-2009, x-ibm-1047-s390, x-ibm-1125_p100-1997, x-ibm-1129_p100-1997, x-ibm-1130_p100-1997, x-ibm-1131_p100-1997, x-ibm-1132_p100-1998, x-ibm-1133_p100-1997, x-ibm-1137_p100-1999, x-ibm-1140-s390, x-ibm-1141-s390, x-ibm-1142-s390, x-ibm-1143-s390, x-ibm-1144-s390, x-ibm-1145-s390, x-ibm-1146-s390, x-ibm-1147-s390, x-ibm-1148-s390, x-ibm-1149-s390, x-ibm-1153-s390, x-ibm-1154_p100-1999, x-ibm-1155_p100-1999, x-ibm-1156_p100-1999, x-ibm-1157_p100-1999, x-ibm-1158_p100-1999, x-ibm-1160_p100-1999, x-ibm-1162_p100-1999, x-ibm-1164_p100-1999, x-ibm-1250_p100-1995, x-ibm-1251_p100-1995, x-ibm-1252_p100-2000, x-ibm-1253_p100-1995, x-ibm-1254_p100-1995, x-ibm-1255_p100-1995, x-ibm-1256_p110-1997, x-ibm-1257_p100-1995, x-ibm-1258_p100-1997, x-ibm-12712-s390, x-ibm-12712_p100-1998, x-ibm-1373_p100-2002, x-ibm-1386_p100-2001, x-ibm-16684_p110-2003, x-ibm-16804-s390, x-ibm-16804_x110-1999, x-ibm-25546, x-ibm-33722_p12a_p12a-2009_u2, x-ibm-37-s390, x-ibm-4517_p100-2005, x-ibm-4899_p100-1998, x-ibm-4909_p100-1999, x-ibm-4971_p100-1999, x-ibm-5123_p100-1999, x-ibm-5351_p100-1998, x-ibm-5352_p100-1998, x-ibm-5353_p100-1998, x-ibm-803_p100-1999, x-ibm-813_p100-1995, x-ibm-8482_p100-1999, x-ibm-901_p100-1999, x-ibm-902_p100-1999, x-ibm-9067_x100-2005, x-ibm-916_p100-1995, x-ibm1006, x-ibm1025, x-ibm1046, x-ibm1097, x-ibm1098, x-ibm1112, x-ibm1122, x-ibm1123, x-ibm1124, x-ibm1153, x-ibm1166, x-ibm1363, x-ibm1364, x-ibm1371, x-ibm1381, x-ibm1383, x-ibm1388, x-ibm1390, x-ibm1399, x-ibm300, x-ibm33722, x-ibm720, x-ibm737, x-ibm833, x-ibm834, x-ibm856, x-ibm867, x-ibm874, x-ibm875, x-ibm921, x-ibm922, x-ibm930, x-ibm933, x-ibm935, x-ibm937, x-ibm939, x-ibm942, x-ibm942c, x-ibm943, x-ibm943c, x-ibm948, x-ibm949, x-ibm949c, x-ibm950, x-ibm954, x-ibm964, x-ibm970, x-ibm971, x-imap-mailbox-name, x-iscii-be, x-iscii-gu, x-iscii-ka, x-iscii-ma, x-iscii-or, x-iscii-pa, x-iscii-ta, x-iscii-te, x-iscii91, x-iso-2022-cn-cns, x-iso-2022-cn-gb, x-iso-8859-11, x-jis0208, x-jis7, x-jis8, x-jisautodetect, x-johab, x-lmbcs-1, x-mac-centraleurroman, x-mac-cyrillic, x-mac-greek, x-mac-turkish, x-macarabic, x-maccentraleurope, x-maccroatian, x-maccyrillic, x-macdingbat, x-macgreek, x-machebrew, x-maciceland, x-macroman, x-macromania, x-macsymbol, x-macthai, x-macturkish, x-macukraine, x-ms932_0213, x-ms950-hkscs, x-ms950-hkscs-xp, x-mswin-936, x-pck, x-sjis_0213, x-unicodebig, x-utf-16le-bom, x-utf-32be-bom, x-utf-32le-bom, x-utf16_oppositeendian, x-utf16_platformendian, x-utf32_oppositeendian, x-utf32_platformendian, x-windows-50220, x-windows-50221, x-windows-874, x-windows-949, x-windows-950, x-windows-iso2022jp I checked the source code and found that the default StringHttpMessageConverter adds the Accept-Charset response header and brings all the character sets! This option needs to be turned off by setting the writeAcceptCharset property.
https://github.com/spring-projec ... ssageConverter.java
Therefore, you need to modify the configuration class just now, and after modifying, it is as follows:
There is no Accept-Charset configuration in the response header.
(End)
|