Mybatis framework A total of four days. The first day: Mybatis introduction Mybatis overview Mybatis environment to build mybatis entry case Custom mybatis framework (the main purpose is to let everyone understand the execution details in mybatis ) Second day: Mybatis basically uses the single table of mybatis crud operating parameters and return values mybatis dao mybatis written details mybatis configured to use several tags Day: mybatis in-depth and multi-table mybatis connection pooling transaction control method and design of mybatis of multi-table queries mybatis one pair Many (many-to-one) many-to-many Day 4: Mybatis cache and annotation development Mybatis loading timing (query timing) Mybatis first level cache and second level cache Mybatis annotation development single-table CRUD multi-table query
02. Correspondence between the three-tier architecture and the ssm framework
1. What is a framework? It is a set of solutions in our software development, and different frameworks solve different problems. The benefits of using the framework: the framework encapsulates a lot of details, so that developers can use a minimalist way to achieve functions. Greatly improve development efficiency. 2. Three-tier architecture presentation layer: the business layer for displaying data : the persistence layer for processing business requirements : it interacts with the database
01 three-tier architecture
03.Analysis of the problem of jdbc operating database
3. Persistence layer technology solution JDBC technology: Connection PreparedStatement ResultSet Spring's JdbcTemplate: Simple encapsulation of jdbc in Spring Apache's DBUtils: It is very similar to Spring's JdbcTemplate, and it is also a simple encapsulation of Jdbc
These are not frameworks. JDBC is a standard Spring’s JdbcTemplate and Apache’s DBUtils are just tools.
04.mybatis overview
4. Overview of mybatis Mybatis is a persistence layer framework, written in java. It encapsulates many details of jdbc operation, so that developers only need to pay attention to the sql statement itself, without having to pay attention to the complicated process of registering drivers, creating connections and so on. It uses ORM ideas to achieve the encapsulation of result sets.
ORM: Object Relational Mappging Simply put: it is to associate the database table with the entity class and the attribute of the entity class so that we can operate the database table by operating the entity class.
user User id userId user_name userName Today we need to keep the attributes in the entity class consistent with the field names of the database table. user data table User entity class id id user_name user_name
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.dao.IUserDao">
<!--配置查询所有-->
<select id="findAll" resultType="com.itheima.domain.User">
select * from user
</select>
</mapper>
Summary of steps to build mybatis environment
07. Precautions for environmental construction
Precautions for setting up the environment: The first one: when creating IUserDao.xml and IUserDao.java, the names are to be consistent with our previous knowledge. In Mybatis, it also calls the operation interface name and mapping file of the persistence layer: Mapper, so: IUserDao and IUserMapper are the same. (Mapper==Dao) Second: When creating a directory in idea, it is different from a package. When the package is created: com.itheima.dao, it is a three-level structure directory. When created: com.itheima.dao It is the third level of the first-level directory : the location of the mapping configuration file of mybatis must be the same as the package structure of the dao interface. The fourth: the value of the namespace attribute of the mapper tag of the mapping configuration file must be the fully qualified class name of the dao interface. The fifth: The operation configuration of the mapping configuration file (select), the value of the id attribute must be the method name of the dao interface
When we comply with the third, fourth, and fifth points, we no longer need to write dao implementation classes in development.