3 回答
TA贡献1786条经验 获得超12个赞
方法声明:
public List<XrayVulnerabilityEntity> findAll(Specification<XrayVulnerabilityEntity> spec, Pageable pageable);
执行:
Specification specification = new Specification<XrayVulnerabilityEntity>() {
@Override
public Predicate toPredicate(Root<XrayVulnerabilityEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
List<Predicate> predicates = new ArrayList<>();
predicates.add(criteriaBuilder.equal(
root.join("domainArtifactId").get("id"), root.get("id")));
predicates.add(criteriaBuilder.and(
root.get("domainArtifactId").get("domainOrgName"), "domainOrgNameString"));
return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
}
};
Pageable page = PageRequest.of(0, 5, new Sort(Sort.Direction.ASC, "id") );
List<XrayVulnerabilityEntity> xrayVulnerabilityEntitylists = xrayVulnerabilityEntityRepo.findAll(specification, page);
TA贡献1811条经验 获得超5个赞
我像这里一样解决了这个问题;
@PostMapping(value = "/search")
public List<Customer> search(@RequestBody List<SearchCriteriaRequest> criteriaRequest, Pageable page) {
if (criteriaRequest == null || criteriaRequest.size() == 0) {
return null;
}
SpecificationsBuilder builder = new SpecificationsBuilder();
for (SearchCriteriaRequest criteria : criteriaRequest) {
builder.with(criteria);
}
Specification<Customer> spec = builder.build();
return customerRepository.findAll(spec, page).getContent();
}
TA贡献2080条经验 获得超4个赞
在此查询中:
@Query("SELECT COUNT(x) FROM XrayVulnerabilityEntity x,DomainArtifactEntity d WHERE d.domainOrgName=:domainOrgNameParam AND x.domainArtifactId=d")
public Long getCount(@Param(value = "domainOrgNameParam") String domainOrgName,Specification<XrayVulnerabilityEntity> spec);
您正在引用一个参数:domainOrgNameParam,但在方法参数中找不到该参数。如果您使用Specifications,您应该在那里定义所有内容并避免传递额外的参数。
添加回答
举报