一、目的
通过Mybatis来操作,删除数据库中的表emp的数据。
二、代码
Emp类
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Emp {
private Integer id;
private String username;
private String password;
private String name;
private Short gender;
private String image;
private Short job;
private LocalDate entrydate;
private Integer deptId;
private LocalDateTime createTime;
private LocalDateTime updateTime;
}
mapper层中的EmpMapper接口
@Mapper
public interface EmpMapper {
//1.根据id删除数据
@Delete("delete from emp where id=#{id} ")
public void delete(Integer id);
}
测试类
@SpringBootTest
class SpringbootMybatisQuickstartApplicationTests {
//操作emp对象
@Autowired
private EmpMapper empMapper;
@Test
public void testDelete() {
empMapper.delete(17);
}
}
三、结果
执行后即可删除id为17的数据。