Mapper層繼承BaseMapper<T>需要引入的pom依賴方式
更新時間:2022年01月19日 11:51:44 作者:qq_43154385
這篇文章主要介紹了Mapper層繼承BaseMapper<T>需要引入的pom依賴方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
Mapper層繼承BaseMapper<T>引入pom依賴
<!-- mp依賴 mybatisPlus 會自動的維護Mybatis 以及MyBatis-spring相關(guān)的依賴 --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>3.0.3</version> </dependency>
Mybatis-Plus的BaseMapper用法
BaseMapper 用法
Mapper 繼承該接口后,無需編寫 mapper.xml 文件,即可獲得CRUD功能
public interface BaseMapper<T> { ? ? //插入一條記錄 ?參數(shù):實體 ?返回:int ? ? Integer insert(T entity); ? ? ? //根據(jù) ID 刪除 ?參數(shù):主鍵ID ?返回:int ? ? Integer deleteById(Serializable id); ? ?? ? ? ?//根據(jù) columnMap 條件,刪除記錄 ?參數(shù):表字段 map 對象 ?返回:int ? ? Integer deleteByMap(@Param("cm") Map<String, Object> columnMap); ? ? ? ?//根據(jù) entity 條件,刪除記錄 ?參數(shù):實體對象封裝操作類(可以為 null) ?返回:int ? ? Integer delete(@Param("ew") Wrapper<T> wrapper); ? ? ? ?//刪除(根據(jù)ID 批量刪除) ?參數(shù):主鍵ID列表 ?返回:int ? ? Integer deleteBatchIds(List<? extends Serializable> idList); ? ? ? ?//根據(jù) ID 修改 ?參數(shù):實體對象 ?返回:int ? ? Integer updateById(T entity); ? ? ? ?//根據(jù) whereEntity 條件,更新記錄 ?參數(shù):實體對象,實體對象封裝操作類(可以為 null) 返回:int ? ? Integer update(@Param("et") T entity, @Param("ew") Wrapper<T> wrapper); ? ? ? ?//根據(jù) ID 查詢 ?參數(shù):主鍵ID ?返回:T ? ? T selectById(Serializable id); ? ? ? ?//查詢(根據(jù)ID 批量查詢) ?參數(shù):主鍵ID列表 ?返回:List<T> ? ? List<T> selectBatchIds(List<? extends Serializable> idList); ? ? ? ?//查詢(根據(jù) columnMap 條件) ?參數(shù):表字段 map 對象 ?返回:List<T> ? ? List<T> selectByMap(@Param("cm") Map<String, Object> columnMap); ? ? ? ?//根據(jù) entity 條件,查詢一條記錄 ?參數(shù):實體對象 ?返回:T ? ? T selectOne(@Param("ew") T entity); ? ? ?//根據(jù) Wrapper 條件,查詢總記錄數(shù) ?參數(shù):實體對象 ?返回:int ? ? Integer selectCount(@Param("ew") Wrapper<T> wrapper); ? ? ? ?//根據(jù) entity 條件,查詢?nèi)坑涗??參數(shù):實體對象封裝操作類(可以為 null) ?返回:List<T> ? ? List<T> selectList(@Param("ew") Wrapper<T> wrapper); ? ? ? ?//根據(jù) Wrapper 條件,查詢?nèi)坑涗??參數(shù):實體對象封裝操作類(可以為 null) 返回:List<T> ? ? List<Map<String, Object>> selectMaps(@Param("ew") Wrapper<T> wrapper); ? ? ? ?//根據(jù) Wrapper 條件,查詢?nèi)坑涗??參數(shù):實體對象封裝操作類(可以為 null) ?返回:List<Object> ? ? List<Object> selectObjs(@Param("ew") Wrapper<T> wrapper); ? ? ? /**? ? ? ?* 用法:(new RowBounds(offset, limit), ew); ? ? ?* 根據(jù) entity 條件,查詢?nèi)坑涗洠ú⒎摚? ? ? ?* @param rowBounds ? ? ?* 分頁查詢條件(可以為 RowBounds.DEFAULT) ? ? ?* @param wrapper ? ? ?* 實體對象封裝操作類(可以為 null) ? ? ?* @return List<T> ? ? ?*/ ? ? ?//根據(jù) ID 刪除 ?參數(shù):主鍵ID ?返回:int ? ? List<T> selectPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper); ? ? ? /** -- 不常用, ? ? ?* 根據(jù) Wrapper 條件,查詢?nèi)坑涗洠ú⒎摚? ? ? ?* @param rowBounds ? ? ?* 分頁查詢條件(可以為 RowBounds.DEFAULT) ? ? ?* @param wrapper ? ? ?* 實體對象封裝操作類 ? ? ?* @return List<Map<String, Object>> ? ? ?*/ ? ? ?//根據(jù) ID 刪除 ?參數(shù):主鍵ID ?返回:int ? ? List<Map<String, Object>> selectMapsPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper); }
用法舉例
接口:
public interface UserDao extends BaseMapper<User> { ?? ?//這里面不用做任何操作 } //具體實現(xiàn)方法中: QueryWrapper<User> queryWrapper=new QueryWrapper<>(); queryWrapper.lambda().eq(User::getName,"zhangsan"); List<User> userList = UserDao.selectList(queryWrapper); //調(diào)用UserDao中的方法
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Mybatis-Plus接口BaseMapper與Services使用詳解
- MybatisPlus?BaseMapper?實現(xiàn)對數(shù)據(jù)庫增刪改查源碼
- mybatis抽取基類BaseMapper增刪改查的實現(xiàn)
- 淺談Mybatis Plus的BaseMapper的方法是如何注入的
- mybatis-plus中BaseMapper入門使用
- MybatisPlus BaseMapper 中的方法全部 Invalid bound statement (not found Error處理)
- Mybatis-Plus BaseMapper的用法詳解
- BaseMapper接口的使用方法
相關(guān)文章
簡單了解Java多態(tài)向上轉(zhuǎn)型相關(guān)原理
這篇文章主要介紹了簡單了解Java多態(tài)向上轉(zhuǎn)型相關(guān)原理,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-12-12SpringBoot?AnnotationUtils工具類的使用實例詳解
這篇文章主要介紹了SpringBoot?AnnotationUtils工具類的使用,使用自定義注解標(biāo)記業(yè)務(wù)方法,原生Java獲取注解及AnnotationUtils工具類獲取方法,本文通過實例代碼給大家介紹的非常詳細,需要的朋友可以參考下2022-09-09SpringBoot項目如何把接口參數(shù)中的空白值替換為null值(推薦)
這篇文章主要介紹了SpringBoot項目如何把接口參數(shù)中的空白值替換為null值(推薦),本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01