MyBatis Basic Knowledge

Source: Internet
Author: User

MyBatis is a data persistence layer (ORM) framework. The mapping relationship between entity class and SQL statement is a semi-automatic ORM implementation.

Advantages of MyBatis: 1. Based on SQL syntax, easy to learn.   2. Ability to understand the underlying assembly process. The 3.SQL statement is encapsulated in the configuration file, which facilitates unified management and maintenance, and reduces the coupling degree of the program. 4. Easy to debug the program.

Comparison with traditional JDBC

Reduced code volume by 61%

The simplest persistence framework

Schema-level performance enhancements

The SQL code is completely detached from the program code and can be reused

Enhanced the Division of labor in the project to enhance the portability of

MyBatis

1. is a framework for SQL statement Mapping (Tools)

2, pay attention to the mapping relationship between Pojo and SQL. does not automatically generate SQL for programmers at run time

3, low level of automation, manual mapping of SQL, high flexibility.

4, developers need to mature the palm according to the SQL statement

There are three types of data sources: unpooled, pooled, JNDI.

Unpooled-this data source implementation simply opens and closes a connection at each request. Although this is a bit slow, it is a good choice for some simple applications that do not require performance and immediate response.

Pooled-this data source cache JDBC Connection object is used to avoid the authentication time required to connect and build the connection instance each time. This approach is popular for concurrent WEB applications because it has the fastest response time.

Jndi-This data source implementation is intended for use with Spring or application services and can be externally configured and referenced within the JNDI context. This data source configuration requires only two properties:

MyBatis has two types of transaction management:

JDBC-This type directly uses the JDBC commit and rollback functionality. It relies on using a connected data source to manage the scope of a transaction.

MANAGED-What this type does not do, it never commits, rolls back, and closes the connection. Instead, let the window manage the entire life cycle of the transaction. (e.g. Spring or Java EE server)

SQL Map File Structure:

? Cache-Configures caching for a given namespace.

? cache-ref– references the cache configuration from other namespaces.

? Resultmap– is the most complex and powerful element to describe how to load objects from a database result set.

? sql– can be reused for SQL blocks, or can be referenced by other statements.

? insert– Mapping INSERT statement

? update– Map UPDATE statement

? delete– Map DELETE Statements

? select– Mapping Query statements

MyBatis Basic Knowledge

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.