在我的一生中,我无法理解为什么在从RestfulController继承的 Controller 中,index方法仅返回4行。这是默认设置吗?当我重写方法时,会发生相同的行为,就像这样。
import grails.rest.*
import grails.converters.*
class WidgitController extends RestfulController {
static responseFormats = ['json', 'xml']
WidgitController() {
super(Widgit)
}
@Override
def index() {
def w = Widgit.findAllWhere(isEnabled: true, [max: 10]) //w: sizec4
def w2 = listAllResources(params) //w2: size 4
respond w
}
}
任何帮助,将不胜感激。
最佳答案
原来,当您查找分页时,该问题会得到更好的关注。
根据域对象的指定方式,gorm将为我们提供不同的resultTransformer。就我而言,我有一对多的关系,被指定为
orders(lazy:false, fetch:"join")
联接的获取告诉gorm进行大查询,然后在应用最大偏移量后减少数据集。
有关更多阅读,请阅读以下内容:
agination-with-hibernate-criteria-and-distinct-root-entity
sorting-and-pagination-with-hibernate-criteria-how-it-can-go-wrong-with-joins
关于hibernate - Grails 3.2中的域对象上是否存在默认的gorm list方法的默认最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40993127/