Introduction to Java Framework---Mybatis

Source: Internet
Author: User

I. Introduction of MyBatis

MyBatis is a first-class persistence framework that supports custom SQL, stored procedures, and advanced mappings. MyBatis almost eliminates all JDBC code and does not need to manually set parameters and retrieve results. MyBatis can be configured with simple XML formats or annotations that map basic data elements, map interfaces, and POJOs (plain Java objects) to records in the database.

Ii. MyBatis Workflow (1) Load configuration and initialize trigger conditions: Load profile configuration from two places, one is the configuration file, one is the Java code annotations, The SQL configuration information is loaded into a Mappedstatement object (including the incoming parameter mapping configuration, executed SQL statement, result mapping configuration), which is stored in memory. (2) Receive call request Trigger condition: Call MyBatis provided API passed in Parameters: for SQL ID and incoming Parameter object processing: Pass the request to the lower level of the request processing layer for processing.  (3) Processing operation request Trigger condition: API Interface Layer Pass the request come over incoming parameter: For SQL ID and pass in Parameter object process: (A) find the corresponding Mappedstatement object based on the SQL ID.  (B) Parse the Mappedstatement object based on the incoming parameter object to get the final SQL to execute and execute the incoming parameters.  (C) obtain a database connection, based on the resulting SQL statements and execute incoming parameters into the database execution, and get the results of the execution.  (D) Conversion processing of the resulting execution results based on the result mapping configuration in the Mappedstatement object and the resulting processing results. (E) Release the connection resources. (4) The return processing result returns the final processing result. The basic idea of ORM tools

Whether it's used hibernate,mybatis or not, you can have one thing in common:

    • The sessionfactory is obtained from the configuration file (usually in the XML configuration file).
    • Session generated by Sessionfactory
    • In the session to complete the deletion of data and other changes and transaction submissions.
    • Close the session after you are done using it.
    • There is a mapping configuration file between the Java object and the database, usually an XML file.
Functional architecture

MyBatis's functional architecture is divided into three tiers:
    1. API Interface Layer: provides interface APIs for external use, where developers manipulate databases through these local APIs. Once the interface layer receives the call request, it invokes the data processing layer to complete the specific data processing.
    2. Data processing layer: Responsible for the specific SQL lookup, SQL parsing, SQL execution and execution result mapping processing and so on. Its primary purpose is to complete a database operation at the request of the call.
    3. Base Support Layer: Responsible for the most basic functional support, including connection management, transaction management, configuration loading and caching processing, these are common things, they are extracted as the most basic components. Provides the most basic support for the data processing layer of the upper layer.

Introduction to Java Framework---Mybatis

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.