更新 - 请参阅评论中的答案
我知道CriteriaQuery.orderBy不支持NULLS LAST.我试图使用TypedQuery并注意到它似乎只是忽略"NULLS LAST"之后的所有内容 - 不会抛出任何错误,只是忽略它:
String sql = "SELECT c FROM Contact c WHERE c.partnerCode =:pCode and c.activeFlag='Y'" +
" ORDER BY c.primaryFlag DESC NULLS LAST, c.lastName ASC";
TypedQuery<Contact> query = em.createQuery(sql, Contact.class);
query.setParameter("pCode", partnerCode);
return query.getResultList();
Run Code Online (Sandbox Code Playgroud)
这将返回由主标志下降排序的结果,首先返回null,忽略对姓氏的排序.
如果我这样做:
String sql = "SELECT c FROM Contact c WHERE c.partnerCode =:pCode and c.activeFlag='Y'" +
" ORDER BY c.primaryFlag DESC, c.lastName ASC";
Run Code Online (Sandbox Code Playgroud)
我得到主要和姓氏排序,但仍然首先得到空值,因为它是一个Oracle数据库.
我最惊讶的是,当我添加NULLS LAST时没有抛出任何错误消息,我希望通过一些语法调整,我可以让它接受NULLS LAST请求.
有没有办法从查询中检索最后X个结果?
例如 - 如果想要前十个结果,我看到这里的例子有效:Spring-Data-JPA注释的setMaxResults?
public interface UserRepository extends Repository<User, Long> {
List<User> findByUsername(String username, Pageable pageable);
}
//and then I could call it like this
Pageable topTen = new PageRequest(0, 10);
List<User> result = repository.findByUsername("Matthews", topTen);
Run Code Online (Sandbox Code Playgroud)
但是如何获得最后十条记录呢?
我能想到的唯一方法就是翻转查询中的顺序(findByUsernameDesc,假设原始结果是升序的),然后向后遍历列表,这样我就可以按照我想要的顺序(升序)处理它.
这似乎是一种丑陋的方式.有没有办法让查询按我想要的顺序给我最后的X结果?
I am getting the following error sporadically. A restart of the Tomcat Server (v7.0) fixes the problem but it reappears after a week or so.
These are the observations:
"Bean property 'id' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?"
The "id" field is annotated with @Id, has valid getter/setter and a restart of the server "fixes" the error for a short period of time. …
我正在创建一个 VB 宏来循环单元格并将值复制并粘贴到记事本中。我想做的是提示用户并询问他们是否愿意在进行下一次迭代之前继续。
Sub LoopTest()
Dim rng As Range, cell As Range
Set rng = Range("A1:A2")
For Each cell In rng
cell.Copy
'Worksheets("Sheet1").Range("A" + j).Copy
Shell "C:\Windows\system32\notepad.exe", vbNormalFocus
SendKeys "^V"
DoEvents
SendKeys "{ENTER}", True
Next cell
End Sub
Run Code Online (Sandbox Code Playgroud)