userRepository.findAll(query)
как показано ниже, и я хочу посмеяться над этим.
Код: Выделить всё
public interface UserRepository extends JpaRepository, JpaSpecificationExecutor {
}
Код: Выделить всё
UserSpecification spec = new UserSpecification();
Specification query = Specification.where(spec.userIdEqual(spec.userIdEqual(userId)))
.and(spec.nameContains(target.getName()))
.and(spec.startDateGreaterThanEqual(target.getStartDate()))
.and(spec.endDateLessThanEqual(target.getEndDate()))
List user = userRepository.findAll(query);
Код: Выделить всё
UserSpecification spec = new UserSpecification();
Specification query = Specification.where(spec.userIdEqual("1"))
.and(spec.nameContains("john")
.and(spec.startDateGreaterThanEqual("2024-1-1"))
.and(spec.endDateLessThanEqual("2024-1-2"))
when(userRepository.findAll(query)).thenReturn(userList)
Подробнее здесь: https://stackoverflow.com/questions/784 ... cification