2015-10-03 1 views
1

Я использую Query DSL с версией 4.0.4, вот мои зависимости;Как получить список/результат из QueryDSL

<dependency> 
    <groupId>com.querydsl</groupId> 
    <artifactId>querydsl-apt</artifactId> 
    <version>4.0.4</version> 
    <scope>provided</scope> 
</dependency> 

<dependency> 
    <groupId>com.querydsl</groupId> 
    <artifactId>querydsl-jpa</artifactId> 
    <version>4.0.4</version> 
</dependency> 

<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-log4j12</artifactId> 
    <version>1.6.1</version> 
</dependency> 

И вот фрагмент моего запроса QueryDSL.

 JPQLQuery query = new JPAQuery(em); 
     QQuotation quotation = QQuotation.quotation; 
     query.from(quotation).where(quotation.ticketNumber.like("this")) 

Однако метод запроса не имеет метод список(), когда я линия .where(quotation.ticketNumber.like("this"))

Вот полный код.

import com.querydsl.jpa.JPQLQuery; 
import com.querydsl.jpa.impl.JPAQuery; 
import org.app.now.domain.process.QQuotation; 
import org.app.now.domain.process.Quotation; 
import org.app.now.repo.QuotationRepoCustom; 
import org.joda.time.LocalDateTime; 
import org.springframework.beans.factory.annotation.Autowired; 

import javax.persistence.EntityManager; 
import java.util.List; 

public class QuotationRepoImpl implements QuotationRepoCustom { 

    @Autowired 
    private EntityManager em; 

    @Override 
    public List<Quotation> search(String ticketNumber, String description, LocalDateTime startDate, LocalDateTime endDate) { 
     System.out.println("Searching"); 
     JPQLQuery query = new JPAQuery(em); 
     QQuotation quotation = QQuotation.quotation; 
     query.from(quotation).where(quotation.ticketNumber.like("this")). 
     return null; 
    } 
} 

ответ

1

Посмотрите на Fechable Интерфейс.

@Override 
public List<Quotation> search(String ticketNumber, String description, LocalDateTime startDate, LocalDateTime endDate) { 
    System.out.println("Searching"); 
    JPQLQuery query = new JPAQuery(em); 
    QQuotation quotation = QQuotation.quotation; 
    return query.from(quotation).where(quotation.ticketNumber.like("this")).fetch(); 
} 

Удачи вам!

0

Как это

@Override 
public List<Quotation> search(String ticketNumber, String description, LocalDateTime startDate, LocalDateTime endDate) { 
    JPQLQuery<Void> query = new JPAQuery<Void>(em); 
    QQuotation quotation = QQuotation.quotation; 
    return query.select(quotation) 
       .from(quotation) 
       .where(quotation.ticketNumber.like("this")) 
       .fetch(); 
}