The recent use of mybatis to do projects when the problem encountered, using MyBatis data for fuzzy query, can only query English, and can not query Chinese, that is: the input parameters for the success of English, Chinese on the search results.
Search a lot of information on the Internet, summed up is the following several situations:
Question one:
JSP page, the project's properties, configuration files, database and other coding formats are unified UTF-8.
Solution: Modify the file encoding format, unified for UTF-8
Question two:
The encoding is not set after the database is installed.
Workaround: Modify the configuration file, the simplest method of perfect modification, modify the character set key value in MySQL's my.cnf file (Note Configuration field details):
1. Add Default-character-set=utf8 to the [client] field as follows:
1
[Client]
2
Port = 3306
3
Socket =/var/lib/mysql/mysql.sock
4
Default-character-set=utf8
2. Add the Character-set-server=utf8 in the [mysqld] field as follows:
1
[Mysqld]
2
Port = 3306
3
Socket =/var/lib/mysql/mysql.sock
4
Character-set-server=utf8
3, in the [MySQL] field to add Default-character-set=utf8, as follows:
1
[MySQL]
2
No-auto-rehash
3
Default-character-set=utf8
After the modification is complete, the service MySQL restart restart MySQL services will take effect.
One more check, OK.
Question three:
There was an error in the Encoding conversion format configuration when the data source was configured.
Solution:
To modify the configuration data source module in the MyBatis configuration file:
<property name= "url" value= "Jdbc:mysql://localhost:3306/cloth?useunicode=true& Characterencoding=utf-8 "/>
Notice here, generally, we are used to writing <property name= "url" value= "Jdbc:mysql://localhost:3306/cloth?useunicode=true& Characterencoding=utf-8 "/>, but in an XML file, its encoding rules determine how to transform it.
There are several types of characters in the XML file that you want to escape from:
|
< |
< |
Less than sign |
|
> |
> |
Greater than sign |
|
& |
& |
, and |
|
' |
' |
Single quotes |
|
" |
" | "
Double quotes
|