当前位置: 首页 > news >正文

MyBatis-Plus 扩展全局方法

1.文件内容

package com.ruoyi.business.mybatisplus.base;import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.IService;import java.util.List;/*** 扩展的 Service 接口* 所有自定义 Service 接口都需要继承此接口** @param <T> 实体类类型*/
public interface BaseService<T> extends IService<T> {/*** 获取表名*/String getTableName();/*** 查询所有数据(忽略自动条件)*/List<T> listAll(Wrapper<T> wrapper);Integer deleteAll(Wrapper<T> wrapper);
}
package com.ruoyi.business.mybatisplus.base;import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;import java.util.*;
import java.util.function.Function;/*** 扩展的 Service 实现类* 所有自定义 Service 实现类都需要继承此类** @param <M> Mapper 类型* @param <T> 实体类类型*/
public class BaseServiceImpl <M extends BaseMapperExt<T>, T>extends ServiceImpl<M, T> implements BaseService<T>{/*** 获取表名*/@Overridepublic String getTableName() {TableInfo tableInfo = TableInfoHelper.getTableInfo(this.entityClass);return tableInfo != null ? tableInfo.getTableName() : "";}/*** 查询所有数据*/@Overridepublic List<T> listAll(Wrapper<T> wrapper) {return baseMapper.selectAll(getTableName(), wrapper);}/*** 删除满足条件的所有数据* @param wrapper* @return*/@Overridepublic Integer deleteAll(Wrapper<T> wrapper) {return baseMapper.deleteAll(getTableName(), wrapper);}
}
package com.ruoyi.business.mybatisplus.base;import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;import java.util.List;/*** 通用Mapper扩展接口* @param <T> 实体类型*/
public interface  BaseMapperExt<T> extends BaseMapper<T> {/*** 查询所有数据(忽略逻辑删除等自动条件)* @param wrapper 查询条件* @return 数据列表*/@Select("SELECT * FROM ${tableName} ${ew.customSqlSegment}")List<T> selectAll(@Param("tableName") String tableName,@Param(Constants.WRAPPER) Wrapper<T> wrapper);@Delete("DELETE FROM ${tableName} ${ew.customSqlSegment}")Integer deleteAll(@Param("tableName") String tableName,@Param(Constants.WRAPPER) Wrapper<T> wrapper);
}

2.引入方式

public interface IMingmenCommemorate3dService extends BaseService<MingmenCommemorate3d>{}
public class MingmenCommemorate3dServiceImpl extends BaseServiceImpl<MingmenCommemorate3dMapper, MingmenCommemorate3d> implements IMingmenCommemorate3dService{}
public interface MingmenCommemorate3dMapper extends BaseMapperExt<MingmenCommemorate3d>
{}

3.调用

 LambdaQueryWrapper<MingmenAlbumImage> wrapperMingmenAlbumImage = Wrappers.lambdaQuery();wrapperMingmenAlbumImage.eq(MingmenAlbumImage::getAlbumId, album.getId());List<MingmenAlbumImage> albumImageList = albumImageService.listAll(wrapperMingmenAlbumImage);albumImageService.deleteAll(wrapperMingmenAlbumImage);

文章转载自:

http://2OzR56sq.ryxdf.cn
http://jTlRG5sw.ryxdf.cn
http://jRRPnPqC.ryxdf.cn
http://UMFC39CM.ryxdf.cn
http://1jA1eu3U.ryxdf.cn
http://QOQB7S2k.ryxdf.cn
http://zQmLSzok.ryxdf.cn
http://QWa98QBi.ryxdf.cn
http://tdJZlzsa.ryxdf.cn
http://j9Gejzyj.ryxdf.cn
http://kb0tb8E4.ryxdf.cn
http://hsJ9ic6r.ryxdf.cn
http://2YLFpIFF.ryxdf.cn
http://D0482eDm.ryxdf.cn
http://JHwnD3Y5.ryxdf.cn
http://FfKRWNAR.ryxdf.cn
http://VfMI2mIB.ryxdf.cn
http://qhLwP2V1.ryxdf.cn
http://gi4B8B7U.ryxdf.cn
http://P7lxwR9r.ryxdf.cn
http://XWdTvKqw.ryxdf.cn
http://klpcQnKU.ryxdf.cn
http://LQZZyq6e.ryxdf.cn
http://ZZHESUEu.ryxdf.cn
http://drB9jGA4.ryxdf.cn
http://sHSfsx80.ryxdf.cn
http://Jo3McgiT.ryxdf.cn
http://rHwypWHq.ryxdf.cn
http://lYGe3OZM.ryxdf.cn
http://Dx7knuWx.ryxdf.cn
http://www.dtcms.com/a/385456.html

相关文章:

  • java中的泛型
  • 使用 AWS Comprehend 综合指南
  • 使用秩和比拟解决非独立同分布情况下的投毒攻击
  • 七、vue3后台项目系列——包装scss、全句变量scss与导入
  • 煤矿山井下绝绝缘监测故障定位
  • 海外分部人员OA请假申请时长为0
  • MySQL --JDBC
  • python使用pyodbc通过不同认证方式连接sqlserver数据源
  • java通过线程池加CompletableFuture实现批量异步处理
  • Coze源码分析-资源库-创建知识库-后端源码-详细流程梳理
  • 极简版 Nginx 反向代理实验步骤
  • python-86-基于Graphviz或Mermaid绘制流程图
  • 智能农机无人驾驶作业套圈路径规划
  • Rayon Rust中的数据并行库入门教程
  • NumPy数组与Python列表的赋值行为解析
  • 基于 AI 的大前端智能家居控制应用开发
  • RAGFlow集成SGLang部署的大模型:实现OpenAI API兼容的自定义LLM调用
  • sqlsever 内存配置错误无法连接,后面恢复连接
  • 51c大模型~合集182
  • 2025.9.15总结
  • 深入理解 Roo Code 的 Code Actions 功能
  • Java---线程池讲解
  • PEFT QLora Deepspeed Zero Stage 3 Offload Trainning
  • 线程概念,控制
  • 扫描仪常见样式:平板与馈纸的特性与适用场景
  • Python进程和线程——多线程
  • 2025年AIOCR审核革命!七大智能费控报销系统终结手工录入
  • 从循环到矩阵运算:矢量化加速机器学习的秘诀
  • R 语言入门实战|第七章 程序:从“老虎机”项目学透流程控制与代码优化
  • clickhouse 中SUM(CASE WHEN ...) 返回什么类型?