Java stores the data in the page in the MySQL database, and the Chinese characters become question marks

  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.
Insert picture description here
  Then it was found that some encoding formats of MySQL had problems.

//在dos中输入以下指令查询编码格式
show variables like 'char%';

Insert picture description here
  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
Insert picture description here
  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.
Insert picture description here

  Save the changes and exit, then restart the MySQL service.
Insert picture description here
  Log in again to view the MySQL encoding format.
Insert picture description here
  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,
Insert picture description here
  there was no problem. The encoding format of the current page was also UTF-8.
Insert picture description here
  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

Insert picture description here

  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.

Guess you like

Origin blog.csdn.net/weixin_46676903/article/details/111253794