SpringDataJpa完成高级查询

EmployeeRepository接口中写方法:
List findByUsernameLike(String username);
List findByUsernameLikeAndAgeGreaterThan(String username, Integer age);
实现:
@Test
public void testFindByUsernameLike(){
    List byUsernameLike = employeeRepository.findByUsernameLike("%1%");
    byUsernameLike.forEach(e -> System.out.println(e));
}

@Test
public void testFindByUsernameLikeAndAgeGreaterThan(){
    List byUsernameLikeAndAgeGreaterThan = employeeRepository.findByUsernameLikeAndAgeGreaterThan("%1%", 39);
    byUsernameLikeAndAgeGreaterThan.forEach(employee -> System.out.println(employee));
}

 

转载于:https://my.oschina.net/u/4107179/blog/3030072

你可能感兴趣的:(SpringDataJpa完成高级查询)