1.repository(dao)层
- repository层创建EmployRepository接口
- 继承JpaRepository接口和JpaSpecificationExecutor接口
@Autowired
private EmployeeRepository employeeRepository;
* 泛型一:要进行CRUD的domain
* 泛型二:domain的主键类型
EmployeeRepository接口继承了JpaRepository<Employee,Long>接口
2.抽取domain中的公共属性
domain类中的所有公共属性和方法都放在BaseDomain父类中
3.测试
@Autowired
private EmployeeRepository employeeRepository;
* 泛型一:要进行CRUD的domain
* 泛型二:domain的主键类型
EmployeeRepository接口继承了JpaRepository<Employee,Long>接口
@Test
public void testSave(){
Employee employee = new Employee();
employee.setUsername("嘀嘀嘀");
employeeRepository.save(employee);
}
@Test
public void testFindAll(){
List<Employee> all = employeeRepository.findAll();
all.forEach(e -> System.out.println(e));
}
@Test
public void testFindOne(){
Employee employee = employeeRepository.findOne(1L);
System.out.println(employee);
}
@Test
public void testDel(){
employeeRepository.delete(7L);
}
@Test
public void testUpdate(){
Employee employee = new Employee();
employee.setId(2L);
employee.setUsername("dididi");
employeeRepository.save(employee);
}