About MyBatis can only query English, can not query the Chinese question

Source: Internet
Author: User

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&amp; 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:

"

&lt;

<

Less than sign

&gt;

>

Greater than sign

&amp;

&

, and

&apos;

'

Single quotes

&quot;

"

Double quotes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.