1.1 What is Mybatis
- MyBatis is an excellent persistence layer framework
- It supports customized SQL, stored procedures, and advanced mapping.
- MyBatis avoids almost all JDBC code and manually setting parameters and obtaining result sets.
- MyBatis can use simple XML or annotations to configure and map native types, interfaces, and Java POJOs (Plain Old Java Objects) as records in the database.
- MyBatis was originally an open source project iBatis of apache . In 2010 this project was migrated from apache software foundation to google code and renamed as MyBatis.
- Migrated to Github in November 2013.
How to get Mybatis?
-
maven repository:
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.2</version> </dependency>
-
Github : https://github.com/mybatis/mybatis-3/releases
-
Chinese document: https://mybatis.org/mybatis-3/zh/index.html
1.2, endurance
Data persistence
- Persistence is the process of transforming program data in a persistent state and a transient state
- Memory: Loss after power off
- Database (Jdbc), io file persistence.
- Life: Refrigerated. Canned.
Why do you need to persist?
-
There are some objects that cannot be lost.
-
Memory is too expensive
1.3, persistence layer
Dao layer, Service layer, Controller layer ...
- The code block to complete the persistence
- Layer boundaries are very obvious.
1.4 Why is Mybatis needed?
- Help the programmer save the data into the database.
- Convenience
- The traditional JDBC code is too complicated. simplify. frame. automation.
- No need for Mybatis. It's easier to get started. Technology is not high or low
- advantage:
- Easy to learn
- flexible
- The separation of SQL and code improves maintainability.
- Provide mapping tags to support the mapping between object and database orm field relationship
- Provide object relationship mapping tags to support object relationship formation and maintenance
- Provide xml tags, support to write dynamic sql.
The most important point: many people use it!
Spring SpringMVC SpringBoot