QueryDsl使用多表关联查询

1、注入EntityManager

@Resource
@PersistenceContext
private EntityManager entityManager;

 

2、注入JPAQueryFactory

private JPAQueryFactory queryFactory;
@PostConstruct
public void init() {
   queryFactory = new JPAQueryFactory(entityManager);
}

 

3、使用JPAQueryFactory进行查询

JPAQuery jpaQuery = queryFactory.select(qUserBuyRecord).
                from(qUserBuyRecord).leftJoin(qCourse).on(qUserBuyRecord.courseId.eq(qCourse.id)).
                offset(pageNum).limit(pageSize).where(predicate);

 

4、获取结果

 QueryResults result = jpaQuery.fetchResults();

 

相关资料:

https://www.cnblogs.com/chenglc/p/11230755.html

你可能感兴趣的:(学习笔记)