Environment:
- JDK1.8
- MySQL5.7
- maven3.6.1
- The Idea to review:
- JDBC
- MySQL
- Java based
- Maven
-
JUnit Framework: Configuration files. Best way: Check the documentation on the website
1, the introduction of
1.1. What is MyBatis
- MyBatis is an excellent persistence layer framework
- It supports custom SQL, stored procedures, and advanced mapping.
- MyBatis eliminates almost all JDBC code and the work of setting parameters and getting result sets.
- MyBatis can configure and map primitive types, interfaces, and Java POJOs (Plain Old Java Objects) to records in the database using simple XML or annotations.
- MyBatis was originally an open source project of Apache iBATIS. In 2010, the project was transferred from Apache Software Foundation to Google Code and renamed as MyBatis. Moved to GitHub in November 2013.
How to get MyBatis?
-
Maven repositories:
Mybatis </groupId> </artifactId> <version>3.5.7</version> </dependency>
- Github:https://github.com/mybatis/my…
- Chinese document: https://mybatis.org/mybatis-3…
1.2. Persistence
Data persistence
- Persistence is the process of transforming program data into persistent and transient states
- Persistent state is stored in the database as long as the database does not delete the database
- Instantaneous state: Memory will be lost when power is cut off
- Database (JDBC), IO file persistence.
Why do you need persistence?
- He had some objects he couldn’t let go of.
-
Memory is too expensive
1.3. Persistence layer
DAO layer, Service layer, Controller layer
- A block of code that does the persistence work
-
The layer boundary is very clear
1.4. Why study MyBatis?
- convenient
- Traditional JDBC code is too complex, simplified, and framed. Advantages:
- Easy to learn
- flexible
- The separation of SQL and code improves maintainability
- Provides a mapping label that supports the mapping of ORM field relationships between objects and databases
- Provides object relational mapping label, support object relational building maintenance
- Provides XML tags to support writing dynamic SQL