The first is to modify the Mysql database encoding and change it to utf-8, the default is latin1 (recommended);
As shown in the figure, find the mysql installation and click on the mysql instance configuration
Keep clicking next to know the following interface:
Remember, the previous circle is a little bit important. . Drop-down box to select utf8
Continue next until:
Write your original password to continue, then continue to Next:
Click to execute
This is OK;
This is done. Remember to delete the original imported project database and re-import it;
Second, modify the jdbc request url to specify the encoding (not recommended)
Add ?useUnicode=true&characterEncoding=UTF-8 after the jdbc url to specify the encoding;
If it is to be escaped in the xml configuration file, ?useUnicode=true&characterEncoding=UTF-8;
For example, in the spring configuration file:
1
2
3
4
5
6
7
|
<!-- 配置数据源 -->
<
bean
id
=
"dataSource"
class
=
"com.alibaba.druid.pool.DruidDataSource"
>
<
property
name
=
"url"
value
=
"jdbc:mysql://localhost:3306/db_blog?useUnicode=true&characterEncoding=UTF-8"
/>
<
property
name
=
"username"
value
=
"root"
/>
<
property
name
=
"password"
value
=
"123456"
/>
</
bean
>
|
The first is recommended;