当我查看OfferHeader的index.gsp时,我只得到" Previous"按钮,当点击它,直到它找到顶部按钮消失。 麻烦的是我需要使用findAllBy-list来获取过滤后的列表,以便响应看起来像这样:
respond offerHeader, model:[offerHeaderCount: offerHeader.count()]
因为不允许offerHeader.count()所以我使用了.size()代替。
控制器索引如下所示:
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
def offerHeader = OfferHeader.findAllByOfferType('o',params)
def count = offerHeader.size()
respond offerHeader, model:[offerHeaderCount: offerHeader.size()]
}
嗯Grails并不喜欢我......
我收到了这个错误:
URI
/offerHeader/index
Class
groovy.lang.MissingPropertyException
Message
null
Caused by
No such property: createCriteria for class: com.torntrading.portal.OfferHeader
Around line 15 of grails-app\controllers\com\torntrading\portal\OfferHeaderController.groovy
12:
13: def index(Integer max) {
14: params.max = Math.min(max ?: 10, 100)
15: def offerHeader = OfferHeader.createCriteria.list( params ) { eq ( "offerType", "o" )}
16:
17: def count = offerHeader.size()
18: respond offerHeader, model:[offerHeaderCount: offerHeader.totalCount
creteCriteria应该像这样使用:
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
def offerHeader = OfferHeader.createCriteria().list( params ) { eq ( "offerType", "o" )}
def count = offerHeader.size()
respond offerHeader, model:[offerHeaderCount: offerHeader.totalCount]
}
答案 0 :(得分:1)
此方案可以更好地进行标准查询:
def offers = OfferHeader.createCriteria().list( params ) {
eq ( "offerType", "o" )
}
respond offers, model: [offerHeaderCount: offers.totalCount]