Springmvc+mybatis+mysql Database Insert Chinese is garbled

Source: Internet
Author: User
Tags java web

Java Web project, the foreground page of the form data, inserted into the database, the results appear garbled "???" The problem of intermittent tossing for a day time, nonsense not to say, steps are as follows:

One: Configuration in Web. XML: Encoded format Interceptor

  

<!--code format blocker--  <filter>    <filter-name>encodingFilter</filter-name>    < filter-class>org.springframework.web.filter.characterencodingfilter</filter-class>    <async-supported>true</async-supported>    <init-param>      <param-name>encoding</param-name>      <param-value>utf-8</param-value >    </init-param>  </filter>  <filter-mapping>    <filter-name> encodingfilter</filter-name>    <url-pattern>/*</url-pattern>  </ Filter-mapping>

 

This ensures that the data passed to the controller is not garbled, and if it is garbled, it should be considered at the database level.

Second: Check the configuration of the database:1. Make sure that the UTF8 is set in the connection URL of the database:
Url:jdbc:mysql://localhost:3306/blog-qwc?useunicode=true&characterencoding=utf-8& Zerodatetimebehavior=converttonull&allowmultiqueries=true

2. Ensure that the database you are creating is configured to support Chinese,

  

Database Properties Support: UTF8--UTF-8 Unicode

Database collation: Utf8_general_ci

3. Modify the encoding of the table blog under the database connection:

ALTER TABLE blog default character set UTF8;

4. Modify the encoding of each field in a table blog:

Change the character set for each column in the table to Utf-8

ALTER TABLE blog change title title varchar (set  UTF8;  ALTER TABLE Blog Change author author varchar (set  UTF8;  ALTER TABLE BLOG Change MD MD varchar (set  UTF8; ALTER TABLE blog change HTML HTML varchar (set UTF8;

NOTE: ALTER TABLE blog change HTML HTML varchar ($) Character set UTF8; field HTML to write two times, no problem

5. If the problem is not resolved, the problem should be the URL of the database connection itself:

To modify a URL in a db.properties file:

Url:jdbc:mysql://localhost:3306/blog-qwc?useunicode=true&amp;characterencoding=utf-8; Zerodatetimebehavior=converttonull;allowmultiqueries=true

Modified to:  

Url:jdbc:mysql://localhost:3306/blog-qwc?useunicode=true&characterencoding=utf-8& Zerodatetimebehavior=converttonull&allowmultiqueries=true

Modified content: &amp = = "&

6. If it doesn't work, delete the database connection and try again

That's the way it is.

Springmvc+mybatis+mysql Database Insert Chinese is garbled

Related Article

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.