MyBatis中文网
https://mybatis.net.cn/
MyBatis 是一款优秀的持久层框架,它支持自定义 SQL、存储过程以及高级映射。MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。MyBatis 可以通过简单的 XML 或注解来配置和映射原始类型、接口和 Java POJO(Plain Old Java Objects,普通老式 Java 对象)为数据库中的记录。
MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。也就是说Mybatis拥有的功能,MybatisPlus全都拥有。所以SpringBoot在集合MyBatis-Plus 时,同时也集合了MyBatis。
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.2.2
com.baomidou mybatis-plus-boot-starter 3.4.2
spring:datasource:druid:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/reggie?serverTimezone=UTCusername: rootpassword: yqqlm@gs1clmybatis-plus:configuration:map-underscore-to-camel-case: truelog-impl: org.apache.ibatis.logging.stdout.StdOutImplmapper-locations: classpath*:/mapper/**/*.xml
Mapper接口中的方法用来操作数据库,调用接口中的方法时,会根据方法名匹配到sql语句。
表所对应的实体类的类名+Mapper.xml
例如:表dish,映射的实体类为Dish,所对应的映射文件为DishMapper.xml
因此一个映射文件对应一个实体类,对应一张表的操作。
Mybatis映射文件用于编写SQL,访问以及操作表中的数据
Mybatis映射文件默认存放的位置是classpath*:/mapper/**/*.xml
@Mapper
public interface DishMapper extends BaseMapper {//Mybatis面向接口编程的两个一致Dish getDishByName(@Param("name") String name);
}