【发布时间】:2014-11-22 15:48:34
【问题描述】:
问题:在域上使用 @Resource 将其公开给休息调用时,我只返回 10 行。当表有 20 行时为什么会这样?这是映射到域的现有表。
测试:使用 Curl 或 Web 浏览器我只返回 10 行。当我打开 SQL 日志记录时,它会排在 TOP 10 吗?在查询中?
SQL 日志:
Hibernate: select count(*) as y0_ from zt6 this_ Hibernate:选择前10个this_.id为id1_1_0_,this_.description为descript2_1_0_ from zt6 this_
为什么是前 10 名??
当我使用 grails 控制台进行测试时,我得到了所有行:
println Dcmnetwork.count()
Hibernate: select count(*) as y0_ from zt6 this_ 20
域名是:
package testrest
import grails.rest.*
@Resource(uri='/test' )
class Dcmnetwork{
int id
String Description
static mapping = {
table 'zt6'
version false
id column: "id"
cache 'read-only'
}
static constraints = {}
}
网页浏览器的输出:
<list>
<dcmnetwork id="1">
<description>Self Test</description>
</dcmnetwork>
<dcmnetwork id="2">
<description>Test 2</description>
</dcmnetwork>
<dcmnetwork id="3">
<description>Test 3</description>
</dcmnetwork>
<dcmnetwork id="4">
<description>Test 4</description>
</dcmnetwork>
<dcmnetwork id="5">
<description>Test 5</description>
</dcmnetwork>
<dcmnetwork id="6">
<description>Test 6</description>
</dcmnetwork>
<dcmnetwork id="7">
<description>Test 7</description>
</dcmnetwork>
<dcmnetwork id="8">
<description>Test 8</description>
</dcmnetwork>
<dcmnetwork id="9">
<description>Test 9</description>
</dcmnetwork>
<dcmnetwork id="10">
<description>Test10</description>
</dcmnetwork>
</list>
【问题讨论】:
-
您可以尝试在查询中添加
max=20或offset=10参数,看看是否有任何变化?看起来自动生成的控制器正在分页结果。
标签: java hibernate rest grails