SpringBoot整合MybatisPlus3.X之SQL注入器(九)
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/p6spy/p6spy -->
<dependency>
<groupId>p6spy</groupId>
<artifactId>p6spy</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.49</version>
<scope>test</scope>
</dependency>
<!-- for testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>application.yml
spring:
datasource:
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
url: jdbc:p6spy:h2:tcp://192.168.180.115:19200/~/mem/test
username: root
password: test实体类
@Data
@TableName(value = "student")
public class Student {
private Long id;
private String name;
private Integer age;
}
@Mapper
public interface StudentMapper extends BaseMapper<Student> {
void deleteAll();
}注入器及方法
public class DeleteAll extends AbstractMethod {
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
/* 执行 SQL ,动态 SQL 参考类 SqlMethod */
String sql = "delete from " + tableInfo.getTableName();
/* mapper 接口方法名一致 */
String method = "deleteAll";
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
return this.addDeleteMappedStatement(mapperClass, method, sqlSource);
}
}
@Component
public class MySqlInjector extends DefaultSqlInjector {
@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
List<AbstractMethod> methodList = super.getMethodList(mapperClass);
//增加自定义方法
methodList.add(new DeleteAll());
return methodList;
}
}测试类
@SpringBootTest
class InjectorApplicationTests {
@Autowired(required = false)
private StudentMapper studentMapper;
@Test
public void test(){
studentMapper.deleteAll();
}
}测试结果
2019-10-31 10:40:22.780 INFO 9484 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
Consume Time:0 ms 2019-10-31 10:40:22
Execute SQL:delete from student
SpringBoot整合MybatisPlus3.X之SQL注入器(九)的更多相关文章
- SpringBoot整合MybatisPlus3.X之SQL执行分析插件(十四)
pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...
- SpringBoot整合MybatisPlus3.X之自定义Mapper(十)
pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...
- SpringBoot整合MyBatis-Plus3.1详细教程
作者:Sans_ juejin.im/post/5cfa6e465188254ee433bc69 一.说明 Mybatis-Plus是一个Mybatis框架的增强插件,根据官方描述,MP只做增强不做改 ...
- SpringBoot整合MybatisPlus3.X之乐观锁(十三)
主要适用场景 意图: 当要更新一条记录的时候,希望这条记录没有被别人更新 乐观锁实现方式: 取出记录时,获取当前version 更新时,带上这个version 执行更新时, set version = ...
- SpringBoot整合MybatisPlus3.X之Wrapper(五)
官方文档说明: 以下出现的第一个入参boolean condition表示该条件是否加入最后生成的sql中 以下代码块内的多个方法均为从上往下补全个别boolean类型的入参,默认为true 以下出现 ...
- SpringBoot整合MybatisPlus3.X之分页插件(四)
注:详细请看2.X博客中,3.X直接上代码. 建议装一个MybatisX插件,可以在Mapper和Xml来回切换 pom.xml <dependencies> <dependency ...
- SpringBoot整合MybatisPlus3.X之逻辑删除(三)
pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...
- SpringBoot整合MybatisPlus3.X之Sequence(二)
数据库脚本 DELETE FROM user; INSERT INTO user (id, name, age, email) VALUES (, , 'test1@baomidou.com'), ...
- SpringBoot整合Mybatisplus3.x之CRUD(一)
pom.xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId& ...
随机推荐
- DeleteFile
import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import org.apac ...
- redis-自动补全
自动补全实现方式有两种: 第一种:数据量非常小时,程序从redis中获取数据后,在程序中排序:redis只作为数据存储用: 第二种:数据量较大时,直接在redis中排序,并返回自动补全的数据. 第三种 ...
- linux 防火墙相关命令
1.系统命令systemctl start firewalld #启动 systemctl status firewalld #查看运行状态 systemctl stop firewalld #关闭 ...
- 使用Docker安装FastDFS(分布式文件系统)
1. 获取镜像 可以利用已有的FastDFS Docker镜像来运行FastDFS. 获取镜像可以通过下载 docker image pull delron/fastdfs 也可是直接使用提前下载的镜 ...
- 电脑链接WiFi有网络不能上网问题
刚刚入手了一个小米book pro笔记本突然发现网络链接了,但是却上不了网.找了n种方法,最后发现问题在于电脑的网络适配器中的无线模式出现了问题,下面开始解决方案的详细步骤说明. 一 . 打开电脑管理 ...
- Cheapest Palindrome POJ - 3280
Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate ...
- MySQL复制从库建立-mysqldump方式
环境准备: master:192.168.0.106:3306slave:192.168.0.105:3306 主和从都必须配置有唯一的ID(server_id:建议ip最后一组+MySQL端口号,例 ...
- 因果推理的春天-实用HTE(Heterogeneous Treatment Effects)论文github收藏
一直以来机器学习希望解决的一个问题就是'what if',也就是决策指导: 如果我给用户发优惠券用户会留下来么? 如果患者服了这个药血压会降低么? 如果APP增加这个功能会增加用户的使用时长么? 如果 ...
- 你真的了解Web前端开发吗?未来前端远比你想的有前途!
近几年来,随着 HTML5.JS 的流行,前端这个职业火热了起来!不少人发出疑惑,前端以后还会更有前途吗? 我只能告诉你:前端不灭 现在都明白了用户体验至上,还要用着舒服 后端提供床,前端提供颜值高的 ...
- Zabbix 2.2系列注入+getsehll
Zabbix 是一个开源的企业级性能监控解决方案. 官方网站:http://www.zabbix.com Zabbix 的jsrpc的profileIdx2参数存在insert方式的SQL注入漏洞,攻 ...