我已经通过@RestController实现了Specification in来设置Specificaton对象中的值。
public ResponseEntity<ServiceResponse> searchUnexpectedLikelyToChurn(@RequestHeader HttpHeaders headers,
@PageableDefault(page = 0, size = 10, sort = "buyer", direction = Direction.ASC) Pageable pageable,
@Conjunction(value = {
@Or({
@Spec(path="buyer", params="search", spec=LikeIgnoreCase.class),
@Spec(path = "email", params = "search", spec = LikeIgnoreCase.class),
@Spec(path = "shipCity", params = "search", spec = LikeIgnoreCase.class),
@Spec(path = "shipState", params = "search", spec = LikeIgnoreCase.class),
@Spec(path = "country", params = "search", spec = LikeIgnoreCase.class)
})}, and = @Spec(path = "company",params = "company", spec = Equal.class)) Specification<CustomerEntity> customerSpec
现在我需要在这个Specification对象上添加另一个条件,它是一个java.util.Date对象,它是根据代码而不是用户输入计算的。我该如何添加?
我目前的DAO实施是:
@Repository
public interface CustomerDao extends JpaRepository<CustomerEntity, Integer>, JpaSpecificationExecutor<CustomerEntity> {
}
答案 0 :(得分:0)
您可以如下使用org.springframework.data.jpa.domain.Specification
界面:
Specification combinedSpec - Specification.where(customerSpec)
.and(calculateAdditionalSpec());
如果您使用旧版的Spring Data JPA,请使用Specifications
帮助程序类。