我在这里使用版本4.0.4的查询DSL是我的依赖项;
<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"))
但是查询方法没有list()方法
当我排队.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;
}
}
答案 0 :(得分: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();
}
祝你好运!
答案 1 :(得分: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();
}