What is mybatis
MyBatis is an excellent persistence layer framework that supports plain SQL queries, stored procedures and advanced mapping. MyBatis eliminates the manual setting of almost all JDBC code and parameters and the retrieval of result sets. MyBatis uses simple XML or annotations for configuration and original mapping, mapping interfaces and Java's POJOs (Plan Old Java Objects, ordinary Java objects) into records in the database.
(I) Program environment
1. jar package
2. Create SqlMapConfig.xml in the classpath directory.
mybatis configuration file. All settings are as follows
At the same time, the parameters of the database can be separated by the properties file, and this time it is separated. properties file is db.properties
To distinguish directories.
Create a new source folder (config) to place the configuration file. The two files are as follows.
SqlMapConfig.xml header
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
3. mapper.xml file (User.xml)
Some CURD statements.
4. SqlMapConfig.xml plus mappper.xml
For example, the mappers tag in 2.
5. Logging
Easy to view the running status.
(II) Testing program and program structure
1. Beginner Program
2. Directory structure
(III) Summary
Create a mybatis environment through configuration files. After that, the statement can be operated through SqlSession. (SQL statement in xml file)
Partial select
update
insert
delete delete