22.06.10 17:48 작성
·
963
0
JPAQuery<User> content = query.selectFrom(user)
.where(
searchQueryCustom(keyword, search),
getIn(userIdListFilterByLanguage)
).orderBy(getSorting(pageable), getDirectionByName(pageable));
private OrderSpecifier<Integer> getSorting(Pageable pageable) {
for (Sort.Order order : pageable.getSort()) {
Order direction = order.getDirection().isAscending() ? Order.ASC : Order.DESC;
switch (order.getProperty()) {
case "email":
return new OrderSpecifier(direction, user.email);
case "sortKorean":
return new OrderSpecifier(direction, new CaseBuilder()
.when(user.name.between("가", "힣")).then(1)
.when(user.name.between("a", "Z")).then(2)
.otherwise(3));
case "sortEnglish":
return new OrderSpecifier(direction, new CaseBuilder()
.when(user.name.between("a", "Z")).then(1)
.when(user.name.between("가", "힣")).then(2)
.otherwise(3));
}
}
return null;
}
private OrderSpecifier<?> getDirectionByName(Pageable pageable) {
for (Sort.Order order : pageable.getSort()) {
return order.getDirection().isAscending() ? user.name.asc() : user.name.desc();
}
return null;
}
select user0_.name
from users user0_
where user0_.uuid in
('0685167f0ebd4d128c8607044e893e60', '081b37bc3661429395d366f015f55f9c', '099dcb0174bd4de693226d8785499431')
order by case when user0_.name between '가' and '힣' then 1 when user0_.name between 'a' and 'Z' then 2 else 3 end asc,
user0_.name asc
limit 10;
select user0_.name
from users user0_
where user0_.uuid in
('0685167f0ebd4d128c8607044e893e60', '081b37bc3661429395d366f015f55f9c', '099dcb0174bd4de693226d8785499431')
order by case when user0_.name between '가' and '힣' then 1 when user0_.name between 'a' and 'Z' then 2 else 3 end ,
user0_.name asc
limit 10;