Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example / wrapper 新增字符串形式的排序方法重载 #34

Merged
merged 1 commit into from
May 8, 2022
Merged

Conversation

ydq
Copy link
Contributor

@ydq ydq commented Apr 20, 2022

#33

使用示例:

// ORDER BY status = 5 DESC , FIELD(`weight`, 3, 1, 4, 2) , create_time DESC
userMapper.wrapper()
                    // 将 状态 等于5的 排序在最前面
                    .orderBy("status = 5 DESC")    
                    // 如果权重不为空 则将指定权重的值放前面
                    .orderBy(weight != null , () -> "`weight` = " + weight + " DESC")    
                    // 如果指定权重列表不为空,则按照指定的权重特顺序进行排序
                    .orderBy(CollectionUtils.isNotEmpty(assignWeightSort),() -> {
                        return assignWeightSort.stream()
                                        .map(Objects::toString)
                                        .collect(Collectors.joining(",", "FIELD(`weight`,", ")"));
                    })
                    // 相同权重的 按照时间倒序
                    .orderBy("create_time DESC");  //  等同于 .orderByDesc(User::getCreateTime);

@abel533
Copy link
Contributor

abel533 commented May 8, 2022

感谢PR 👍

@abel533 abel533 merged commit 62ad39f into mybatis-mapper:develop May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants