網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
一、簡(jiǎn)介
在MybatisPlus中,BaseMapper中定義了一些常用的CRUD方法,當(dāng)我們自定義的Mapper接口繼承BaseMapper后即可擁有了這些方法。
二、BaseMapper中的CRUD方法
通用 CRUD 封裝BaseMapper接口,為 Mybatis-Plus 啟動(dòng)時(shí)自動(dòng)解析實(shí)體表關(guān)系映射轉(zhuǎn)換為 Mybatis 內(nèi)部對(duì)象注入容器
泛型 T 為任意實(shí)體對(duì)象
參數(shù) Serializable 為任意類型主鍵 Mybatis-Plus 不推薦使用復(fù)合主鍵約定每一張表都有自己的唯一 id 主鍵
對(duì)象 Wrapper 為 條件構(gòu)造器
/*
* Copyright (c) 2011-2020, hubin (jobob@qq.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.baomidou.mybatisplus.core.mapper;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
/**
* <p>
* Mapper 繼承該接口后,無(wú)需編寫 mapper.xml 文件,即可獲得CRUD功能
* </p>
* <p>
* 這個(gè) Mapper 支持 id 泛型
* </p>
*
* @author hubin
* @since 2016-01-23
*/
public interface BaseMapper<T> {
/**
* <p>
* 插入一條記錄
* </p>
*
* @param entity 實(shí)體對(duì)象
*/
int insert(T entity);
/**
* <p>
* 根據(jù) ID 刪除
* </p>
*
* @param id 主鍵ID
*/
int deleteById(Serializable id);
/**
* <p>
* 根據(jù) columnMap 條件,刪除記錄
* </p>
*
* @param columnMap 表字段 map 對(duì)象
*/
int deleteByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
/**
* <p>
* 根據(jù) entity 條件,刪除記錄
* </p>
*
* @param queryWrapper 實(shí)體對(duì)象封裝操作類(可以為 null)
*/
int delete(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
/**
* <p>
* 刪除(根據(jù)ID 批量刪除)
* </p>
*
* @param idList 主鍵ID列表(不能為 null 以及 empty)
*/
int deleteBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
/**
* <p>
* 根據(jù) ID 修改
* </p>
*
* @param entity 實(shí)體對(duì)象
*/
int updateById(@Param(Constants.ENTITY) T entity);
/**
* <p>
* 根據(jù) whereEntity 條件,更新記錄
* </p>
*
* @param entity 實(shí)體對(duì)象 (set 條件值,不能為 null)
* @param updateWrapper 實(shí)體對(duì)象封裝操作類(可以為 null,里面的 entity 用于生成 where 語(yǔ)句)
*/
int update(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) Wrapper<T> updateWrapper);
/**
* <p>
* 根據(jù) ID 查詢
* </p>
*
* @param id 主鍵ID
*/
T selectById(Serializable id);
/**
* <p>
* 查詢(根據(jù)ID 批量查詢)
* </p>
*
* @param idList 主鍵ID列表(不能為 null 以及 empty)
*/
List<T> selectBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
/**
* <p>
* 查詢(根據(jù) columnMap 條件)
* </p>
*
* @param columnMap 表字段 map 對(duì)象
*/
List<T> selectByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
/**
* <p>
* 根據(jù) entity 條件,查詢一條記錄
* </p>
*
* @param queryWrapper 實(shí)體對(duì)象
*/
T selectOne(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
/**
* <p>
* 根據(jù) Wrapper 條件,查詢總記錄數(shù)
* </p>
*
* @param queryWrapper 實(shí)體對(duì)象
*/
Integer selectCount(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
/**
* <p>
* 根據(jù) entity 條件,查詢?nèi)坑涗? * </p>
*
* @param queryWrapper 實(shí)體對(duì)象封裝操作類(可以為 null)
*/
List<T> selectList(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
/**
* <p>
* 根據(jù) Wrapper 條件,查詢?nèi)坑涗? * </p>
*
* @param queryWrapper 實(shí)體對(duì)象封裝操作類(可以為 null)
*/
List<Map<String, Object>> selectMaps(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
/**
* <p>
* 根據(jù) Wrapper 條件,查詢?nèi)坑涗? * 注意: 只返回第一個(gè)字段的值
* </p>
*
* @param queryWrapper 實(shí)體對(duì)象封裝操作類(可以為 null)
*/
List<Object> selectObjs(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
/**
* <p>
* 根據(jù) entity 條件,查詢?nèi)坑涗洠ú⒎?yè))
* </p>
*
* @param page 分頁(yè)查詢條件(可以為 RowBounds.DEFAULT)
* @param queryWrapper 實(shí)體對(duì)象封裝操作類(可以為 null)
*/
IPage<T> selectPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
/**
* <p>
* 根據(jù) Wrapper 條件,查詢?nèi)坑涗洠ú⒎?yè))
* </p>
*
* @param page 分頁(yè)查詢條件
* @param queryWrapper 實(shí)體對(duì)象封裝操作類
*/
IPage<Map<String, Object>> selectMapsPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
}
三、MybatisPlus的QueryWrapper和UpdateWrapper應(yīng)用
Mybatis-plus的wrapper構(gòu)造條件使用如下圖所示:

附上MybatisPlus官網(wǎng): https://mp.baomidou.com/guide/crud-interface.html#mapper-crud-%E6%8E%A5%E5%8F%A3
原文鏈接:https://blog.csdn.net/fygkchina/article/details/128624602
- 上一篇:沒(méi)有了
- 下一篇:沒(méi)有了
相關(guān)推薦
- 2022-12-13 使用Idea調(diào)試RocketMQ源碼教程_服務(wù)器其它
- 2022-09-08 Go語(yǔ)言中的Iota關(guān)鍵字_Golang
- 2022-04-12 ASP動(dòng)態(tài)include文件_ASP基礎(chǔ)
- 2024-01-06 RocketMQ死信消息解決方案
- 2023-07-06 golang中time包時(shí)間處理
- 2022-08-15 Python?time模塊之時(shí)間戳與結(jié)構(gòu)化時(shí)間的使用_python
- 2022-08-26 一篇文章學(xué)會(huì)GO語(yǔ)言中的變量_Golang
- 2022-05-27 Go批量操作excel導(dǎo)入到mongodb的技巧_Golang
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支