spring boot to query the database to get the object properties Chinese garbled

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_35959554/article/details/88352344

1, first check the database field is coded collation is set to utf8_general_ci 

2 Check the database stored in garbled data, if it is garbled, then the problem is that we pass the data in the database.

  • Controller inspection process is set as follows, for example
@RequestMapping(value = "/addStu", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")

  With produces = "application / json; charset = UTF-8 to a predetermined coding format

  • Check the following is provided application.properties
spring.datasource.url = jdbc:mysql://localhost:3306/数据库名?characterEncoding=utf8

  characterEncoding = utf8 ensures that encode the write data to the database is utf8

Other aspects of coding problems caused by too much online, there are solutions you can try to introduce a

https://blog.csdn.net/qq_39654841/article/details/81156695

You can see Soso, I just share my steps to find out the problem, I hope everyone is good enough.

Guess you like

Origin blog.csdn.net/weixin_35959554/article/details/88352344