CRUD
SAVE
Boolean save (T entity) ;
Boolean saveBatch (Collection<T> entityList) ;
Boolean saveBatch (Collection<T> entityList, int batchSize) ;
参数说明
类型
参数名
描述
T
entity
实体对象
Collection
entityList
实体对象集合
int
batchSize
插入批次数量
SaveOrUpdate -- 一般来说是根据主键来进行判断的
boolean saveOrUpdate (T entity) ;
boolean saveOrUpdate (T entity, Wrapper<T> updateWrapper) ;
boolean saveOrUpdateBatch (Collection<T> entityList) ;
boolean saveOrUpdateBatch (Collection<T> entityList, int batchSize) ;
参数说明
类型
参数名
描述
T
entity
实体对象
Wrapper
updateWrapper
实体对象封装操作类 UpdateWrapper
Collection
entityList
实体对象集合
int
batchSize
插入批次数量
Remove
boolean remove (Wrapper<T> queryWrapper) ;
boolean removeById (Serializable id) ;
boolean removeByMap (Map<String, Object> columnMap) ;
boolean removeByIds (Collection<? extends Serializable> idList) ;
参数说明
类型
参数名
描述
Wrapper
queryWrapper
实体包装类 QueryWrapper
Serializable
id
主键ID
Map<String, Object>
columnMap
表字段 map 对象
Collection<? extends Serializable>
idList
主键ID列表
Update
boolean update (Wrapper<T> updateWrapper) ;
boolean update (T entity, Wrapper<T> updateWrapper) ;
boolean updateById (T entity) ;
boolean updateBatchById (Collection<T> entityList) ;
boolean updateBatchById (Collection<T> entityList, int batchSize) ;
参数说明
类型
参数名
描述
Wrapper
updateWrapper
实体对象封装操作类 UpdateWrapper
T
entity
实体对象
Collection
entityList
实体对象集合
int
batchSize
更新批次数量
Get
T getById (Serializable id) ;
T getOne (Wrapper<T> queryWrapper) ;
T getOne (Wrapper<T> queryWrapper, boolean throwEx) ;
Map<String, Object> getMap (Wrapper<T> queryWrapper) ;
<V> V getObj (Wrapper<T> queryWrapper, Function<? super Object, V> mapper) ;
参数说明
类型
参数名
描述
Serializable
id
主键ID
Wrapper
queryWrapper
实体对象封装操作类 QueryWrapper
boolean
throwEx
有多个 result 是否抛出异常
T
entity
实体对象
Function<? super Object, V>
mapper
转换函数
List
List<T> list () ;
List<T> list (Wrapper<T> queryWrapper) ;
Collection<T> listByIds (Collection<? extends Serializable> idList) ;
Collection<T> listByMap (Map<String, Object> columnMap) ;
List<Map<String, Object>> listMaps () ;
List<Map<String, Object>> listMaps (Wrapper<T> queryWrapper) ;
List<Object> listObjs () ;
<V> List<V> listObjs (Function<? super Object, V> mapper) ;
List<Object> listObjs (Wrapper<T> queryWrapper) ;
<V> List<V> listObjs (Wrapper<T> queryWrapper, Function<? super Object, V> mapper) ;
参数说明
类型
参数名
描述
Wrapper
queryWrapper
实体对象封装操作类 QueryWrapper
Collection<? extends Serializable>
idList
主键ID列表
Map<?String, Object>
columnMap
表字段 map 对象
Function<? super Object, V>
mapper
转换函数
Page
IPage<T> page (IPage<T> page) ;
IPage<T> page (IPage<T> page, Wrapper<T> queryWrapper) ;
IPage<Map<String, Object>> pageMaps (IPage<T> page) ;
IPage<Map<String, Object>> pageMaps (IPage<T> page, Wrapper<T> queryWrapper) ;
参数说明
类型
参数名
描述
IPage
page
翻页对象
Wrapper
queryWrapper
实体对象封装操作类 QueryWrapper
Count
int count () ;
int count (Wrapper<T> queryWrapper) ;
参数说明
类型
参数名
描述
Wrapper
queryWrapper
实体对象封装操作类 QueryWrapper
Chain
query
QueryChainWrapper<T> query () ;
LambdaQueryChainWrapper<T> lambdaQuery () ;
query().eq("column" , value).one();
lambdaQuery().eq(Entity::getId, value).list();
update
UpdateChainWrapper<T> update () ;
LambdaUpdateChainWrapper<T> lambdaUpdate () ;
update().eq("column" , value).remove();
lambdaUpdate().eq(Entity::getId, value).update(entity);
Mapper CRUD 接口
说明:
通用 CRUD 封装BaseMapper (opens new window) 接口,为 Mybatis-Plus
启动时自动解析实体表关系映射转换为 Mybatis
内部对象注入容器
泛型 T
为任意实体对象
参数 Serializable
为任意类型主键 Mybatis-Plus
不推荐使用复合主键约定每一张表都有自己的唯一 id
主键
对象 Wrapper
为 条件构造器
Insert
int insert (T entity) ;
参数说明
Delete
int delete (@Param(Constants.WRAPPER) Wrapper<T> wrapper) ;
int deleteBatchIds (@Param(Constants.COLLECTION) Collection<? extends Serializable> idList) ;
int deleteById (Serializable id) ;
int deleteByMap (@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap) ;
参数说明
类型
参数名
描述
Wrapper
wrapper
实体对象封装操作类(可以为 null)
Collection<? extends Serializable>
idList
主键ID列表(不能为 null 以及 empty)
Serializable
id
主键ID
Map<String, Object>
columnMap
表字段 map 对象
Update
int update (@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) Wrapper<T> updateWrapper) ;
int updateById (@Param(Constants.ENTITY) T entity) ;
参数说明
类型
参数名
描述
T
entity
实体对象 (set 条件值,可为 null)
Wrapper
updateWrapper
实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
Select
T selectById (Serializable id) ;
T selectOne (@Param(Constants.WRAPPER) Wrapper<T> queryWrapper) ;
List<T> selectBatchIds (@Param(Constants.COLLECTION) Collection<? extends Serializable> idList) ;
List<T> selectList (@Param(Constants.WRAPPER) Wrapper<T> queryWrapper) ;
List<T> selectByMap (@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap) ;
List<Map<String, Object>> selectMaps (@Param(Constants.WRAPPER) Wrapper<T> queryWrapper) ;
List<Object> selectObjs (@Param(Constants.WRAPPER) Wrapper<T> queryWrapper) ;
IPage<T> selectPage (IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper) ;
IPage<Map<String, Object>> selectMapsPage (IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper) ;
Integer selectCount (@Param(Constants.WRAPPER) Wrapper<T> queryWrapper) ;
参数说明
类型
参数名
描述
Serializable
id
主键ID
Wrapper
queryWrapper
实体对象封装操作类(可以为 null)
Collection<? extends Serializable>
idList
主键ID列表(不能为 null 以及 empty)
Map<String, Object>
columnMap
表字段 map 对象
IPage
page
分页查询条件(可以为 RowBounds.DEFAULT)
mapper 层 选装件
说明:
选装件位于 com.baomidou.mybatisplus.extension.injector.methods.additional
包下 需要配合Sql 注入器 使用,案例(opens new window)
使用详细见源码注释(opens new window)
int alwaysUpdateSomeColumnById (T entity) ;
int insertBatchSomeColumn (List<T> entityList) ;
int deleteByIdWithFill (T entity) ;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!