前面我們將了Spring Boot集成Mybatis相關的操作,而在Mybatis-plus則是基於Mybatis進行了更加豐富的基礎功能提供和封裝,比如預置了大量的默認方法以及分頁組件。
比如其中提供的BaseMapper,用於其他業務Mapper的集成接口變定義瞭如下常見的功能的接口:
public interface BaseMapper<T> extends Mapper<T> {
/**
* 插入一條記錄
*
* @param entity 實體對象
*/
int insert(T entity);
/**
* 根據 ID 刪除
*
* @param id 主鍵ID
*/
int deleteById(Serializable id);
/**
* 根據 columnMap 條件,刪除記錄
*
* @param columnMap 表字段 map 對象
*/
int deleteByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
/**
* 根據 entity 條件,刪除記錄
*
* @param wrapper 實體對象封裝操作類(可以爲 null)
*/
int delete(@Param(Constants.WRAPPER) Wrapper<T> wrapper);
/**
* 刪除(根據ID 批量刪除)
*
* @param idList 主鍵ID列表(不能爲 null 以及 empty)
*/
int deleteBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
/**
* 根據 ID 修改
*
* @param enti