Please refer to Mybatis official website for specific usage
MybatisPlus universal CRUD interface
Before the order
MybatisPlus general CRUD interface MybatisPlus conditional constructor MybatisPlus code generator tutorial details The configuration of MybatisPlus
Service A universal CRUD interface
Save
// Insert a record (select field, policy insert)
- boolean save(T entity)
- boolean saveBatch(Collection<T> entityList)
- boolean saveBatch(Collection<T> entityList, int batchSize)
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
T | entity | Entity objects |
Collection | entityList | Entity object collection |
int | batchSize | Insert lot quantity |
SaveOrUpdate
// TableId annotation has update record, no insert record
boolean saveOrUpdate(T entity);
// Try updating according to updateWrapper, if not proceed with saveOrUpdate(T)
boolean saveOrUpdate(T entity, Wrapper<T> updateWrapper);
// Batch modify inserts
boolean saveOrUpdateBatch(Collection<T> entityList);
// Batch modify inserts
boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize);
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
T | entity | Entity objects |
Wrapper | updateWrapper | The entity object encapsulates the action class UpdateWrapper |
Collection | entityList | Entity object collection |
int | batchSize | Insert lot quantity |
Remove
// Delete the record according to the entity condition
boolean remove(Wrapper<T> queryWrapper);
// Delete by ID
boolean removeById(Serializable id);
// Delete the record according to the columnMap condition
boolean removeByMap(Map<String, Object> columnMap);
// Delete (delete by ID)
boolean removeByIds(Collection<? extends Serializable> idList);
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
Wrapper | queryWrapper | Entity wrapper class QueryWrapper |
Serializable | id | The primary key ID |
Map<String, Object> | columnMap | Table field map object |
Collection<? extends Serializable> | idList | Primary key ID list |
Update
// SqlSET is required to update records according to the UpdateWrapper condition
boolean update(Wrapper<T> updateWrapper);
// Update the record according to the whereWrapper condition
boolean update(T updateEntity, Wrapper<T> whereWrapper);
// Select modify according to ID
boolean updateById(T entity);
// Batch update by ID
boolean updateBatchById(Collection<T> entityList);
// Batch update by ID
boolean updateBatchById(Collection<T> entityList, int batchSize);
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
Wrapper | updateWrapper | The entity object encapsulates the action class UpdateWrapper |
T | entity | Entity objects |
Collection | entityList | Entity object collection |
int | batchSize | Update batch quantity |
Get
// Query by ID
T getById(Serializable id);
// Query a record according to Wrapper. The result set, if multiple, will throw an exception, randomly taking one wrapper with a constraint. Last ("LIMIT 1")
T getOne(Wrapper<T> queryWrapper);
// Query a record according to Wrapper
T getOne(Wrapper<T> queryWrapper, boolean throwEx);
// Query a record according to Wrapper
Map<String, Object> getMap(Wrapper<T> queryWrapper);
// Query a record according to Wrapper
<V> V getObj(Wrapper<T> queryWrapper, Function<? super Object, V> mapper);
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
Serializable | id | The primary key ID |
Wrapper | queryWrapper | The entity object encapsulates the action class QueryWrapper |
boolean | throwEx | Whether more than one result throws an exception |
T | entity | Entity objects |
Function<? super Object, V> | mapper | The transition function |
List
// Query all
List<T> list(a);
// Query the list
List<T> list(Wrapper<T> queryWrapper);
// query (by ID)
Collection<T> listByIds(Collection<? extends Serializable> idList);
// Query (based on columnMap condition)
Collection<T> listByMap(Map<String, Object> columnMap);
// Query all lists
List<Map<String, Object>> listMaps();
// Query the list
List<Map<String, Object>> listMaps(Wrapper<T> queryWrapper);
// Query all records
List<Object> listObjs(a);
// Query all records
<V> List<V> listObjs(Function<? super Object, V> mapper);
// Query all records according to the Wrapper condition
List<Object> listObjs(Wrapper<T> queryWrapper);
// Query all records according to the Wrapper condition
<V> List<V> listObjs(Wrapper<T> queryWrapper, Function<? super Object, V> mapper);
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
Wrapper | queryWrapper | The entity object encapsulates the action class QueryWrapper |
Collection<? extends Serializable> | idList | Primary key ID list |
Map<? String, Object> | columnMap | Table field map object |
Function<? super Object, V> | mapper | The transition function |
Page
// Unconditional paging query
IPage<T> page(IPage<T> page);
// Conditional paging query
IPage<T> page(IPage<T> page, Wrapper<T> queryWrapper);
// Unconditional paging query
IPage<Map<String, Object>> pageMaps(IPage<T> page);
// Conditional paging query
IPage<Map<String, Object>> pageMaps(IPage<T> page, Wrapper<T> queryWrapper);
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
IPage | page | Flip the object |
Wrapper | queryWrapper | The entity object encapsulates the action class QueryWrapper |
Mapper universal CRUD interface
Insert
// Insert a record
int insert(T entity);
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
T | entity | Entity objects |
Delete
// Delete the record according to the entity condition
int delete(@Param(Constants.WRAPPER) Wrapper<T> wrapper);
// Delete (delete by ID)
int deleteBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
// Delete by ID
int deleteById(Serializable id);
// Delete the record according to the columnMap condition
int deleteByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
Wrapper | wrapper | Entity objects encapsulate operation classes (can be null) |
Collection<? extends Serializable> | idList | Primary key ID list (cannot be null and empty) |
Serializable | id | The primary key ID |
Map<String, Object> | columnMap | Table field map object |
Update
// Update the record according to the whereWrapper condition
int update(@Param(Constants.ENTITY) T updateEntity, @Param(Constants.WRAPPER) Wrapper<T> whereWrapper);
// Change according to ID
int updateById(@Param(Constants.ENTITY) T entity);
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
T | entity | Entity object (set conditional value, can be null) |
Wrapper | updateWrapper | The entity object encapsulates the action class (which can be null, where the entity is used to generate the WHERE statement) |
Select
// Query by ID
T selectById(Serializable id);
// Query a record based on the entity condition
T selectOne(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// query (by ID)
List<T> selectBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
// Query all records according to entity condition
List<T> selectList(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// Query (based on columnMap condition)
List<T> selectByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
// Query all records according to the Wrapper condition
List<Map<String, Object>> selectMaps(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// Query all records according to the Wrapper condition. Note: Only the value of the first field is returned
List<Object> selectObjs(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// Query all records according to entity condition (and turn the page)
IPage<T> selectPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// Query all records according to the Wrapper condition (and flip the page)
IPage<Map<String, Object>> selectMapsPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
// Query the total number of records according to the Wrapper condition
Integer selectCount(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
Copy the code
- Parameters that
type | Parameter names | describe |
---|---|---|
Serializable | id | The primary key ID |
Wrapper | queryWrapper | Entity objects encapsulate operation classes (can be null) |
Collection<? extends Serializable> | idList | Primary key ID list (cannot be null and empty) |
Map<String, Object> | columnMap | Table field map object |
IPage | page | Paging query criteria (can be rowbound.default) |