![](/img/trans.png)
[英]No primary or default constructor found for interface org.springframework.data.jpa.domain.Specification] with root cause
[英]How to modify a org.springframework.data.jpa.domain.Specification object?
我已經在@RestController中實現了Specification,以在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
而且我使用了這個庫[ https://github.com/tkaczmarzyk/specification-arg-resolver#enabling-spec-annotations-in-your-spring-app] 。
現在,我需要在此Specification對象上添加另一個條件,它是一個java.util.Date對象,它是根據代碼而不是用戶輸入計算的。 如何添加呢?
我當前的DAO實現是:
@Repository
public interface CustomerDao extends JpaRepository<CustomerEntity, Integer>, JpaSpecificationExecutor<CustomerEntity> {
}
您可以使用org.springframework.data.jpa.domain.Specification
接口,如下所示:
Specification combinedSpec - Specification.where(customerSpec)
.and(calculateAdditionalSpec());
如果您使用舊版本的Spring Data JPA,請使用Specifications
助手類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.