我正在尝试使用status
和OpenOn(date)
两个字段使用动态查找器进行搜索。这个查询运行良好:
render(view:'list', model:[incidentInstanceList:Incident.findAllByStatusIlikeAndOpenOnGreaterThan("closed",new Date()-1,[sort:"id",order:"desc"])])
但现在我正在尝试使用动态查找器搜索三个字段,即UserId
,status
和OpenOn(date)
:
render(view:'list', model:[incidentInstanceList:Incident.findAllByStatusIlikeuserIdIlikeAndOpenOnGreaterThan("closed","${session.user.userId}",new Date()-1,[sort:"id",order:"desc"])])
此查询无法正常运行并显示错误:
No signature of method: app.Incident.findAllByStatusIlikeuserIdIlikeAndOpenOnGreaterThan() is applicable for argument types: (java.lang.String, org.codehaus.groovy.runtime.GStringImpl, java.util.Date, java.util.LinkedHashMap) values: [closed, tt10004, Wed Aug 24 15:12:21 IST 2011, [sort:id, order:desc]] Possible solutions: findAllByStatusIlikeuserIdIlikeAndCreatedOnGreaterThan(java.util.List)
请指导我解决这个问题。
答案 0 :(得分:7)
def incidentInstanceList = {
def criteria = Incident.createCriteria()
def results = criteria {
and {
user {
like('userId', "${session.user.userId}").toString()
}
like('status', "Closed" )
gt('closedOn',new Date()-1)
sort("id", "desc")
}
}
render(view:'list', model:[ incidentInstanceList: results, incidentInstanceTotal: Incident.count()])
}
答案 1 :(得分:4)
答案 2 :(得分:1)
可能是这样的东西,顺便说一下,对我来说似乎更清晰:
def incidentInstanceList =
Incident.createCriteria().list
{
eq(status, 'closed')
ilike(userId, "${session.user.userId}")
gt(openOn, new Date()-1)
sort("id", "desc")
}
答案 3 :(得分:0)
此外我认为没有必要放第二个参数""只做session.user.userId(我假设你不需要userId在这里成为String)createCriteria是你需要的:)