javaEEday09-Mybatis-基础操作-删除

This commit is contained in:
xx
2026-10-18 15:11:17 +08:00
parent 19cc314870
commit adeca945b6
2 changed files with 17 additions and 0 deletions
@@ -1,8 +1,12 @@
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("delete from emp where id = #{id};")
int delete(Integer id);//想返回删除数据的个数
// void delete(Integer id);//不想获得删除数据的个数
} }
@@ -1,13 +1,26 @@
package com.inmind; package com.inmind;
import com.inmind.mapper.EmpMapper;
import org.junit.jupiter.api.AutoClose;
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
public void testDelete(){
int deleteCount = empMapper.delete(16);
System.out.println("删除数据的条数:"+deleteCount);
}
} }