我有一些='B777-%' WHERE
个对象可以有LIKE '777-%';
UPDATE
和SET
,我希望它们按名称排序,然后通过电子邮件排序,但首先会显示没有空名称的用户。我是这样想的:
='B787-%' WHERE
结果我首先得到名字,但不是通过电子邮件排序。
答案 0 :(得分:1)
这可以通过Java-8的Comparator实用程序轻松完成:
List<User> users = Arrays.asList(new User("pete", "pete@email"), new User(null, null), new User("alex", null), new User(null, "email"));
Collections.sort(users, Comparator.comparing(User::getName, Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(Comparator.comparing(User::getEmail, Comparator.nullsLast(Comparator.naturalOrder()))));
System.out.println(users);
输出:
[
User{name='alex', email='null'},
User{name='pete', email='pete@email'},
User{name='null', email='email'},
User{name='null', email='null'}
]