When I was writing a springboot project today, when I saved the value input on the page into the database, I found that the fields storing Chinese characters in the database table became question marks.
I started the investigation from the database, and the encoding format of the database was fine.
Then it was found that some encoding formats of MySQL had problems.
//在dos中输入以下指令查询编码格式
show variables like 'char%';
Then I found my-default.ini in the MySQL folder, changed it to my.ini, the location remained the same (my MySQL is version 5.6) and
added the following
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
[mysqld] This should be available by default, just add the other two.
Save the changes and exit, then restart the MySQL service.
Log in again to view the MySQL encoding format.
It is found that the database and server have not changed, but they are obviously changed in my.ini. Later, I learned from the Internet that you need to upgrade MySQL to 8 before you can modify it, so the MySQL encoding format is not going on for the time being. (Actually, I don’t think the problem lies here.)
After I checked the encoding format of my eclipse,
there was no problem. The encoding format of the current page was also UTF-8.
When I was at a loss, I suddenly found the database connection in application.yml. The url lacks encoding configuration, splice the following code behind the url
?useUnicode=true&characterEncoding=UTF-8
After I insert the data again, the value in the database can be displayed correctly.
The above is a problem I encountered during this development. The coding problem may lie in many places. I hope this experience will inspire you.