An article in layman's language take you mybatis

What is mybatis:

Mybatis is essentially a semi-automated ORM framework, formerly known as ibatis, in addition to pojo and mapping relationships, but also need some sql statement.

How to treat ORM framework:

Deal with conflict, java programmers like object-oriented development-oriented interface development, and the database is a picture of a table and a library consisting of relationship between the two is difficult to reconcile, while relational mapping to solve this problem.

Mybatis mapping file three elements: SQL; mapping rules; Pojo;

Why mybatis instead of hibernate?

In our Internet environment inside, we often have to face huge amounts of data, so we have to tune based on the capabilities of the underlying is sql statement. The hibernate generated sql statement is very opaque.

Mybatis core processes three stages:

Initialization phase, reads the configuration information in the XML configuration files and annotations, create analytic object, and the completion of initialization of each module. It is to load our configuration file into memory inside. When sqlSession initialization loaded into memory to go.

Agent stage, encapsulation iBatis programming model, using the initialization mapper interface development;

Data write stage, to complete the mapping SqlSession by SQL parsing, parameter, SQL execution result of reflection resolution process.

SqlSession

SqlSession means creating a database session, representing a connection to the database;

Mybatis provide external data access is the main API;

In fact SqlSession functions are implemented based on Excutor.

Mybatis of two programming models Mybatis encapsulates ibatis programming model, using sqlsession provide external access to the database. There is also a mapper programming interface used to access the database

The difference Mybatis and ibatis

Mybatis formerly known as the ibatis, before ibatis is Apache's products, and later to Google's, but Google found ibatis to implement a lot of trouble, but also need to maintain a static variable, and there is no business meaning. So Google changed mybatis, through an interface-oriented way, so that all the code have business meaning, shield the complexity of the underlying code.

Why mapper interfaces can access the database of it?

In fact, it is finally turned into ibatis underlying execution method, it uses dynamic proxy configuration file reading +, find the corresponding session in the method of execution, to find the namespace and method name of the method. Pass parameters.

Or business processes must first instantiate sqlssessionFactory, load the database configuration files and mapper.xml to configuration objects. Then get sqlsession object. Then dynamic proxies across the interface for programming and programming ibatis gap, followed finally jdbc specification, the object underlying the four completion by cooperation.

Like the author of this article can give a point like, look, will share Java-related articles every day! There are benefits presented from time to time, including the consolidation of learning materials, interview questions, such as source code ~ ~

Guess you like

Origin blog.51cto.com/14440597/2422964