简体   繁体   English

Grails 3.2中的域对象上是否存在默认的max to gorm list方法

[英]Is there a default max to gorm list method on domain object in grails 3.2

For the life of me I cannot understand why in a controller that inherits from RestfulController, that the index method only returns 4 rows. 对于我一生,我无法理解为什么在从RestfulController继承的控制器中,index方法仅返回4行。 Is this a default setting? 这是默认设置吗? The same behavior happens when I override the method, like so. 当我重写方法时,会发生相同的行为,就像这样。

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
    }
}

Any help would be appreciated. 任何帮助,将不胜感激。

Turns out the problem comes under better focus when you look up paging. 原来,当您查找分页时,该问题会得到更好的关注。

depending on how your domain objects are spec'd out gorm will us a different resultTransformer. 根据域对象的指定方式,gorm将为我们提供不同的resultTransformer。 In my case I had a one to many relationship that was spec'd as 就我而言,我与一对多关系被指定为

orders(lazy:false, fetch:"join")

the fetch as join told gorm to do a large query and then reduce the set of data after the max offset was applied. 联接的获取告诉gorm进行大查询,然后在应用最大偏移量后减少数据集。

for more reading look into the following: 有关更多阅读,请阅读以下内容:

agination-with-hibernate-criteria-and-distinct-root-entity 冬眠准则和明显的根实体搅动

sorting-and-pagination-with-hibernate-criteria-how-it-can-go-wrong-with-joins 冬眠标准的排序和分页如何与联接出错

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM