mybatisplus-sql注入器
sql注入器
使用mybatisplus只需要继承BaseMapper接口即可使用;但是有新的需求需要扩展BaseMapper里面的功能时可使用sql注入器。
扩展BaseMapper里面的功能
点击查看代码
public interface UserMapper extends BaseMapper<User> {
List<User> findAll();
}
实现FindAll方法
点击查看代码
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
public class FindAll extends AbstractMethod {
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
String sql = "select * from " + tableInfo.getTableName();
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
return this.addSelectMappedStatementForTable(mapperClass,"findAll",sqlSource,tableInfo);
}
}
定义sql注入器
点击查看代码
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.example.mybatisplusdemo.sample.method.FindAll;
import java.util.List;
public class MyInject extends DefaultSqlInjector {
@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
methodList.add(new FindAll());
return methodList;
}
}
将sql注入器注册到Spring容器中
点击查看代码
@Bean
public MyInject inject(){
return new MyInject();
}
Mybatis-Plus中使用sql注入器场景:mapper 层 选装件
int alwaysUpdateSomeColumnById(T entity);
int insertBatchSomeColumn(List entityList);
int logicDeleteByIdWithFill(T entity);
mybatisplus-sql注入器的更多相关文章
- MyBatis-Plus 3.0.3 Sql注入器添加,即全局配置Sql注入器,sqlInjector改写
官网上写着 但是,这个其实是2.0系列的写法,由于引用了最新的3.0.3这个功能基本不好使. 3.0.3版本的写法 也就是中间加了一层,原来是AutoSqlInjector,现在改为AbstractS ...
- SpringBoot整合MybatisPlus3.X之SQL注入器(九)
pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...
- MybatisPlus SQL 打印控制台
#applicaton.yml 配置 mybatis-plus: configuration: # 是否将sql打印到控制面板(该配置会将sql语句和查询的结果都打印到控制台) log-impl: o ...
- Mybatis-Plus的应用场景及注入SQL原理分析
一.背景 1.1 传统Mybatis的弊端 1.1.1 场景描述 假设有两张表:一张商品表.一张订单表,具体表的字段如下: 现有如下需求: 分别根据id查询商品表和订单表所有信息 根据支付状态和通知状 ...
- mybatisplus打印sql语句
package com.osplat.config; import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; ...
- mybatis-plus 3.X 配置
官网配置参数说明地址:https://mp.baomidou.com/config/#logicdeletevalue 本地配置:yml mybatis-plus: mapper-locations: ...
- MyBatis-Plus初步使用
在使用mybatis的过程中,我们会发现需要自己写很多的mapper和mapper.xml配置文件,很多时候会写到相当多的重复代码,特别是普通的增删改查,这样不仅会影响我们的开发效率,也会使得代码变的 ...
- SpringBoot 使用Mybatis-Plus
简介 Mybatis-Plus(简称MP)是一个 Mybatis 的增强工具,在 Mybatis 的基础上只做增强不做改变,为简化开发.提高效率而生. 特性 无侵入:Mybatis-Plus 在 My ...
- Spring Boot Mybatis-Plus
Mybatis-Plus 是对 Mybatis-Plus 的一些扩充. 在 Spring Boot 中进行集成的时候其实基本上和 mybatis 是一致的. 在你的配置文件中.配置 你的 entity ...
- springboot 零xml集成mybatis-plus
工程结构 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&quo ...
随机推荐
- 【freertos】011-信号量、互斥量及优先级继承机制源码分析
目录 前言 11.1 任务同步 11.2 信号量概念 11.3 二值信号量 11.3.1 二值信号量概念 11.3.2 优先级翻转 11.3.3 二值信号量运作机制 11.4 计数信号量 11.4.1 ...
- jupyter notebook修改默认浏览器
1. anaconda集成了python以及各种库.python和anaconda可二选一. 2. anaconda或python安装后记得把pip源改为国内的镜像源地址.比如163,阿里,清华以及南 ...
- JS:变量的作用域
1.作用域: 指一个变量它在哪些代码范围能够被使用,这些地方就是变量的作用域 JS中的两种作用域: 1.全局作用域.2.函数作用域 2.在es5中 函数的代码块内部的代码 可以访问形参变量 也可 ...
- npm发布包以及更新包还有需要注意的几点问题(这里以发布vue插件为例)
前言 在此之前,你需要去npm官网注册一个属于自己的账号,记住自己的账户名以及密码.邮箱,后面会用的到.第一步,安装webpack简易框架 vue init webpack-simple marque ...
- UiPath剪贴板操作的介绍和使用
一.剪切板操作的介绍 模拟用户使用剪切板操作的一种行为: 例如使用设置剪切板(SettoClipboard),从剪切板获取(GetfromClipboard)的操作 二.剪切板相关操作在UiPath中 ...
- lerna源码阅读
能够找到入口文件 能够本地调试
- XXXX系统测试计划
XXXX系统测试计划 目录 XXXX系统测试计划 目标 概述 项目背景 适用范围 组织形式 组织架构图 角色及职责 测试工作分工 团队协作 测试对象 应测试特性 不被测试特性 测试任务安排 系统测试任 ...
- springboot2+jpa+oracle实例
pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="ht ...
- C++对象的应用
本篇文章将介绍对象数组,对象的动态分配以及对象在函数中的应用. 一.对象数组 1.对象数组的定义和初始化 定义对象数组与定义普通数组的语法形式基本相同.如定义一个Square obj[3]:表示一个正 ...
- shell脚本语句
条件语句 1.if语句 语法格式: if [ expression ] then 命令 elif [ expression ] then 命令 -- else 命令 fi if语句有单分支结构,双分支 ...