我的控制器中有使用动态查找器的列表代码
def listPurchaseRequest(Integer max){
params.max = Math.min(max ?: 5, 100)
def purchaseRequestList = PurchaseRequest.list (params)
if ( params.query) {
purchaseRequestList = PurchaseRequest.findAllByRequestByLikeOrRequestNumberLike("%${params.query}%", "%${params.query}%", params)
}
[purchaseRequestInstanceList: purchaseRequestList,
purchaseRequestInstanceTotal: //this]
}
我的搜索和列表正在工作,除了我的分页。
<g:paginate total="${purchaseRequestInstanceTotal}" params="${params}" maxsteps="3" prev="«" next="»" />
如果我使用purchaseRequestList.totalCount
它可以使用默认列表,但是当我搜索后显示结果时,它会给我Exception evaluating property 'totalCount' for java.util.ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: totalCount for class: rms.PurchaseRequest
错误
如果我使用purchaseRequestList.count()
它会给我Could not find which method count() to invoke from this list: public java.lang.Number java.util.Collection#count(groovy.lang.Closure) public java.lang.Number java.util.Collection#count(java.lang.Object)
错误
答案 0 :(得分:2)
您需要使用CountBy*
方法进行搜索。试试这个
def listPurchaseRequest(Integer max){
params.max = Math.min(max ?: 5, 100)
def purchaseRequestList, count
if (params.query) {
purchaseRequestList = PurchaseRequest.findAllByRequestByLikeOrRequestNumberLike("%${params.query}%", "%${params.query}%", params)
count = PurchaseRequest.countByRequestByLikeOrRequestNumberLike("%${params.query}%", "%${params.query}%")
} else {
purchaseRequestList = PurchaseRequest.list (params)
count = purchaseRequestList.totalCount
}
[purchaseRequestInstanceList: purchaseRequestList,
purchaseRequestInstanceTotal: count]
}
仅供参考,我将.list()
移至else
条款,以便在list
设置时保存您同时调用findBy
和params.query
。