1.Spring-mybatis-删除实现-SQL注入

This commit is contained in:
2025-09-25 15:46:07 +08:00
parent 4040b06ab8
commit 784f2e5603
3 changed files with 24 additions and 0 deletions

View File

@@ -1,8 +1,19 @@
package com.inmind.mapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface EmpMapper {
/*
员工删除的接口方法
delete from emp where id = 17;
#{id}:直接将接口方法中传入的参数使用预编译的方式动态拼接到sql语句中实现功能的动态化
${id}:直接将参数拼接到sql中
*/
// @Delete("delete from emp where id = ${id};")
// public void delete(Integer id);
@Delete("delete from emp where id = #{id};")
public int delete(Integer id);
}

View File

@@ -12,3 +12,6 @@ spring.datasource.url=jdbc:mysql://localhost:3306/mybatis
spring.datasource.username=root
#连接数据库的密码
spring.datasource.password=1234
#输出mybatis的日志
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

View File

@@ -1,13 +1,23 @@
package com.inmind;
import com.inmind.mapper.EmpMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SpringbootMybatisCrudApplicationTests {
@Autowired
private EmpMapper empMapper;
@Test
void contextLoads() {
}
@Test
void testDelete(){
int count = empMapper.delete(15);
System.out.println(count);
};
}