스프링 포럼에 대한 답장을 얻지 못했기 때문에 여기에서 사용해 보겠습니다.QueryDslRepositorySupport를 인터페이스 리포지토리와 함께 사용하면
@NoRepositoryBean
public interface CommonRepository<T> extends JpaRepository<T, Long>, QueryDslPredicateExecutor<T> {
T getById(final long id);
}
@Repository
public interface ConcreteRepository extends CommonRepository<ConcreteEntity> {
List<ConcreteEntity> getByNameAndAddress(final String name, final String address);
}
public class ConcreteRepositoryImpl extends QueryDslRepositorySupport implements ConcreteRepository {
private BooleanExpression nameEquals(final QConcreteEntity entity, final String name) {
return entity.eq(name);
}
public List<ConcreteEntity> getByNameAndAddress(final String name, final String address) {
QConcreteEntity entity = QConcreteEntity.concreteEntity;
return from(entity).where(entity.name.eq(name).and(entity.address.eq(address))).list(entity);
}
}
구현의 문제 I는 각 구체적인 클래스 getById(final long id)
을 구현해야한다는 것입니다 :
인터페이스에서 다음과 같은 방법을 확장 공통 인터페이스 저장소를 가지고 있나요. 나는 그것을하고 싶지 않다. 일반적으로 스프링 데이터는 각 엔티티에 대해 자동으로 알 수 있습니다. 또한 QueryDslRepositorySupport
의 기능을 갖고 싶습니다. 그것을 해결하는 방법이 있나요
select .. from concreteentity en where en.id = ...
: 내 예에서 는 일반적으로 같은 것을 생성 그것? 이미 Spring Jpa adding custom functionality to all repositories and at the same time other custom funcs to a single repository
및
우연히하지만 이러한 솔루션이 도움이됩니다 생각하지 않는다 나는 완전히 내가 문제를 해결하는 데 사용할 수있는 방법을 이해하지 않습니다.기독교
감사합니다, QuerydslRepositorySupport
에서 일반적인 getById을 만들 수
처럼 당신이 당신의 질문의 끝 부분에있는 링크를 해결할 수있다? –
@ TimoWestkämper : 고쳤습니다. 죄송합니다. –
이것에 대해서도 전문가의 의견을 듣고 싶습니다. 나는 단순한 대답은 엔티티를위한 별개의 querydsl 저장소를 만들 필요가 있다고 생각한다. 표준 저장소와는 별도로,하지만 절름발이가 보인다. – chrismarx