1

在 SQL 中,我们有“选择前 10 行”,因此只会选择前 10 行。JPA查询语言中是否有任何方法可以达到相同的效果?

4

2 回答 2

2

You can add setMaxResults(10) to your Query in code.

For instance:

TypedQuery<MyObject> query = entityManager.createNamedQuery("MyObject.findAll", MyObject.class).setMaxResults(10);
于 2013-04-27T01:34:41.230 回答
2

创建 JPA 查询对象时,可以对其调用以下方法:

query.setFirstResult(0)

query.setMaxResults(10)

于 2013-04-27T01:35:43.617 回答