Writing method and simple use of mybatis configuration file

First meeting mybatis

At first, Apache had an open source project of Batis, which was put in Google Code. Later, it was migrated to GitHub for some reasons, which is today's mybatis

What is mybatis?

Mybatis is an excellent persistence layer framework that supports customized SQL, stored procedures, and advanced mapping. Mybatis avoids almost all JDBC code and manually setting parameters and extracting result sets. Mybatis uses simple XML or annotations to configure and map primitives, and maps interfaces and Java POJOs (plain old Java objects) into records in the database.

MyBatis3. x

Here is a brief introduction to mybatis, and the specific use methods will be posted in the code.

Mybatis's past and present life

The predecessor of mybatis is ibatis. Ibatis was originally developed by Clinton begin and later donated to Apache foundation to establish ibatis open source project. In May 2010, the project was migrated from apahce foundation to Google Code and renamed mybatis.

Nevertheless, its package structure is still ibatis.

www.mybatis. org/

https://github.com/mybatis

Introduction to mybatis

Mybatis is a data persistence layer (ORM) framework. The mapping relationship between entity classes and SQL statements is a semi-automatic ORM implementation.

Advantages of mybatis:

1. Based on SQL syntax, it is easy to learn.

2. Be able to understand the bottom assembly process.

3. SQL statements are encapsulated in the configuration file, which is convenient for unified management and maintenance and reduces the coupling degree of the program.

4. Convenient program debugging.

All SQL statements are defined in XML (recommended). They can also be implemented on the interface by annotation. These mapping files are called mappers.

Comparison with traditional JDBC

61% less code

The simplest persistence framework

Architecture level performance enhancements

SQL code is completely separated from program code and can be reused

Enhanced division of labor in the project

Enhanced portability

canMyBatisDemo

Package and class distribution diagram:

Mybatis has only one package and one database support package.

mybatis-config. XML configuration file (of course, the file name can be taken at will, but try to conform to the specification. Refer to the manual for configuration files)

sqlSessionUtils. java

User. java

Mapping file for user XML (the simplest configuration file)

UserMapper. Java (interface, it is officially recommended to use the interface mode - safer)

Demo1. java

User2. xml

This is the first time I've seen mybatis. I know how to use it simply and how to use it in complex ways. I'll post it next time (crud of the database and some details in the process of using it).

The above is the writing method and simple use of mybatis configuration file introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>