具体使用请参考官网Mybatis官网
MybatisPlus通⽤ CRUD接口
前序
一文带你了解MybatisPlus基本使用
Spring、SpringBoot整合Mybatis-Plus详细教程
MybatisPlus通⽤ CRUD接口
MybatisPlus之条件构造器
MybatisPlus中代码生成器教程详解
MybatisPlus之配置
Service通用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 updateEntity, Wrapper<T> whereWrapper);
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|
Mapper通用CRUD接口
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 updateEntity, @Param(Constants.WRAPPER) Wrapper<T> whereWrapper);
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) |