Model
pojo 类继承 Model 抽象类,即可获得 CRUD(增删改查)功能。Model 使用映射类 pojo 继承 Model 抽象类,直接使用该类可以进行 CRUD,但是必须存在对应的 xxMapper 继承 BaseMapper。
Mapper
Mapper 用于 service 层,通过 xxMapper 调用从 Mapper 继承的方法。
BaseMapper 实现了 Mapper 接口。
xxMapper 类继承 BaseMapper 接口后,无需编写 mapper.xml 文件,即可获得 CRUD(增删改查)功能。BaseMapper 支持 id 为泛型。
BaseMapper 是使用 dao 层数据进行 CRUD,只需要进行使用 dao 层接口继承 BaseMapper 接口即可。
Mapper.class
package com.baomidou.mybatisplus.core.mapper;
public interface Mapper<T> {
}
Mapper.class 为空接口,作为顶层 Mapper 只用于说明规范,具体看其实现类。
Iservice
Iservice 用于 controller 层,通过 service 调用。使用 service 调用进行 CRUD,需要使用 service 接口继承 Iservice,并且 service 接口的实现类要继承 ServiceImpl<xxxMapper, pojo>。
Mapper 和 Iservice 的区别
- Mapper 用于 service 层,通过 xxMapper 调用从 Mapper 继承的方法。
- Iservice 用于 controller 层,通过 service 调用从 Iservice 继承的方法。
Mappper 和 Iservice 里面提供的方法都差不多,只是Iservice提供了批量操作的实现,比如: 批量添加、批量修改。
Wrapper
xxMapper 继承 BaseMapper 接口时,继承了其中的空方法,Wrapper 代码生成器的作用是为了动态向 sql 的 CRUD(增删改查)语句,即装饰从 BaseMapper 继承的 sql 语句,Wrapper 就是典型的修饰器模型。
本文介绍了在SpringBoot项目中,如何通过MybatisPlus利用Model和Mapper进行CRUD操作,区分Mapper和Iservice的职责,以及Wrapper在动态SQL生成中的作用。Mapper用于Service层,而Iservice则在Controller层提供批量操作功能。
21万+

被折叠的 条评论
为什么被折叠?



