package cn.x.test;
import cn.x.domain.Department;
import cn.x.mapper.DepartmentMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
@SpringBootTest
@RunWith(SpringRunner.class)
@Slf4j
public class DepartmentMapperTest {
@Autowired
private DepartmentMapper departmentMapper;
@Test //查询所有
public void findAll(){
List<Department> departments = departmentMapper.selectList(null);
for (Department department : departments) {
log.error(department.toString());
}
}
@Test //新增
public void saveDept(){
Department department = new Department();
department.setSn("sn1001");
department.setName("我是测试数据");
//调用mapper执行添加操作
departmentMapper.insert(department);
}
@Test //根据主键进行修改
public void update(){
Department department = new Department();
department.setId(55L);
department.setName("测试是我");
department.setDirPath("2021-09-11");
departmentMapper.updateById(department);
}
@Test //根据主键删除
public void delete(){
departmentMapper.deleteById(55L);
}
}