你可以将控制器列表参数与Hibernate标准结合起来吗? [英] Can you combine controller list params with Hibernate criteria?

查看:64
本文介绍了你可以将控制器列表参数与Hibernate标准结合起来吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,您可以直接将params传递给下面的样板代码:

  [fooInstanceList:Foo。 list(params),fooInstanceTotal:Foo.count()] 

是否可以传递params作为一个Hibernate标准的一部分,例如下面的那个?

  def c = Foo.createCriteria()
def results = c {
not {eq(bar,test)}
}

[fooInstanceList:results,fooInstanceTotal:results.size()]

我正在使用max和offset参数,因此我可以将它用于分页。我也想使用count来计算所有非分页结果。我认为results.size()只会给我分页结果,而不是所需的非分页结果。我会如何去解决这个问题?

解决方案

您可以使用 params while使用标准。我想你有一个不使用 c.list
$ b

  def的错字c = Foo.createCriteria()
def results = c.list(params){
not {eq(bar,test)}
}

假设 params max 偏移



标准返回一个 PagedResultList ,您可以从中获取totalCount。因此

  results.totalCount //results.getTotalCount()

应该为您提供总数,但总会有第二个查询触发以获得总数。在这种情况下,Hibernate会为你做,而不是你明确地做。


I have noticed that you can pass "params" straight in to the boilerplate code below:

[fooInstanceList: Foo.list(params), fooInstanceTotal: Foo.count()]

Is it possible to pass "params" in as part of a Hibernate criteria for example the one below?

def c = Foo.createCriteria()
    def results = c {
        not { eq("bar","test") }
    }

    [fooInstanceList: results, fooInstanceTotal: results.size()]

I am looking to use the "max" and "offset" params so I can use it for paging for example. I would also like to use the equivalent of count that counts all non-paged results. I think results.size() would only give me paged results, instead of the desired non-paged results. How would I go about this?

解决方案

You can use params while using the criteria. I suppose you have a typo of not using c.list

def c = Foo.createCriteria()
def results = c.list(params) {
    not { eq("bar","test") }
}

Assuming params has max and offset.

Criteria returns a PagedResultList where you can get the totalCount from it. So

results.totalCount //results.getTotalCount()

should give you the total count, although there is always a second query fired to get the total count. In this case Hibernate does that for you instead of you doing it explicitly.

这篇关于你可以将控制器列表参数与Hibernate标准结合起来吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆