@GET
@Path("/colors/{params: .*}")
@Produces(MediaType.APPLICATION_JSON)
public List<Espece> findByColors(@PathParam("params") List<PathSegment> params){
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Espece> cq = cb.createQuery(Espece.class);
Root<Espece> birdType = cq.from(Espece.class);
Join<Espece, Couleur> couleurs = birdType.join(Espece_.colors);
List<Predicate> restrictions = new ArrayList<>();
for(PathSegment param : params){
restrictions.add(cb.equal(cb.lower(couleurs.get(Couleur_.nom)), param.toString().toLowerCase()));
}
cq.where(cb.and(restrictions.toArray(new Predicate[]{})));
/*cq.select(birdType)
.where(restrictions.toArray(new Predicate[]{}));*/
return getEntityManager().createQuery(cq).getResultList();
}
조류를 하나 또는 여러 색상으로 검색하는 방법이 있습니다 (조류는 둘 이상의 색상을 가질 수 있음). 그리고 단 하나의 색으로 검색 할 때 : http://localhost:8084/NataRest/bird/colors/black 잘 동작합니다. 그러나 두 가지 색상으로 검색 할 때 : http://localhost:8084/NataRest/bird/colors/black/yellow 그것은 나에게 빈 대답을 제공합니다 (예, 검정색과 노란색의 데이터베이스에 새가 있습니다). 여러 포럼을 확인했지만 여전히이 작업을 수행 할 방법을 찾지 못했습니다 ... '또는'및 '고유'로 조합을 만들 수 있습니다. 하지만 내가 원하는 교차로가 아닙니다 :/두 조건 사이에 교차 (and)를 만드는 내 쿼리가 작동하지 않습니다. 이유가 무엇입니까? (Hibernate, Java, Rest Application)
도움을 주셔서 감사합니다! 오칸.