흰 스타렉스에서 내가 내리지

[Querydsl] ORDER BY RAND() 사용하기 본문

JPA

[Querydsl] ORDER BY RAND() 사용하기

주씨. 2024. 5. 5. 18:05
728x90
.orderBy(Expressions.numberTemplate(Double.class, "function('rand')").asc())

 

queryFactory
        .select(Projections.constructor(CurationSimpleResponseDto.class,
                curation.id, curation.title, curation.description, curation.cnt, curation.thumbnail, curationBookmark.status))
        .from(curation)
        .leftJoin(curationBookmark)
        .on(curationBookmark.curation.id.eq(curation.id).and(curationBookmark.member.id.eq(memberId)))
        .orderBy(Expressions.numberTemplate(Double.class, "function('rand')").asc())
        .fetch();