[JPA] 많이 사용하는 QueryDSL 조건 종류

QueryDSL을 사용하면서 많이 사용했던 조건 종류를 작성해본다.


eq()

1
member.userRoles.eq(AuthorityName.USER) // user_roles = 'USER'

ne() 또는 eq().not()

1
2
member.userRoles.ne(AuthorityName.ADMIN) // user_roles != 'ADMIN'
member.userRoles.eq(AuthorityName.ADMIN).not() // user_roles != 'ADMIN'

isNull()

1
member.deletedAt.isNull() // deleted_at IS NULL

isNotNull()

1
member.emailVerifiedAt.isNotNull() // email_verified_at IS NOT NULL

between()

1
member.createdAt.between(startDateTime, endDateTime) // created_at between '2024-04-01 00:00:00' and '2024-04-24 23:59:59'

goe()

1
member.createdAt.goe(startDateTime) // created_at >= '2024-04-01 00:00:00'

loe

1
member.createdAt.loe(endDateTime) // created_at <= '2024-04-24 23:59:59'

gt

1
member.createdAt.gt(startDateTime) // created_at > '2024-04-01 00:00:00'

lt

1
member.createdAt.lt(endDateTime) // created_at < '2024-04-24 23:59:59'

like

1
2
// 임의로 %
member.email.like("%joyoungjae") // LIKE '%joyoungjae'

notLike

1
2
// 임의로 %
member.email.notLike("joyoungjae%") // NOT LIKE 'joyoungjae%'

contains

1
2
// 앞뒤에 %
member.email.contains("joyoungjae") // LIKE '%joyoungjae%'

startsWith

1
2
// 뒤에 %
member.email.startsWith("joyoungjae") // LIKE 'joyoungjae%'

endsWith

1
2
// 뒤에 %
member.email.endsWith("joyoungjae") // LIKE '%joyoungjae'

in

1
member.id.in(1, 3, 5, 7, 9) // id IN (1, 3, 5, 7, 9)

notIn

1
member.id.notIn(2, 4, 6, 8) // id NOT IN (2, 4, 6, 8)

Categories:

Updated:

Leave a comment