1.Spring-mybatis-删除实现-SQL注入
This commit is contained in:
@@ -1,8 +1,19 @@
|
|||||||
package com.inmind.mapper;
|
package com.inmind.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface EmpMapper {
|
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);
|
||||||
}
|
}
|
||||||
|
@@ -12,3 +12,6 @@ spring.datasource.url=jdbc:mysql://localhost:3306/mybatis
|
|||||||
spring.datasource.username=root
|
spring.datasource.username=root
|
||||||
#连接数据库的密码
|
#连接数据库的密码
|
||||||
spring.datasource.password=1234
|
spring.datasource.password=1234
|
||||||
|
|
||||||
|
#输出mybatis的日志
|
||||||
|
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
|
@@ -1,13 +1,23 @@
|
|||||||
package com.inmind;
|
package com.inmind;
|
||||||
|
|
||||||
|
import com.inmind.mapper.EmpMapper;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class SpringbootMybatisCrudApplicationTests {
|
class SpringbootMybatisCrudApplicationTests {
|
||||||
|
@Autowired
|
||||||
|
private EmpMapper empMapper;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testDelete(){
|
||||||
|
int count = empMapper.delete(15);
|
||||||
|
System.out.println(count);
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user