我正在使用动态查找器进行搜索,但是当我在其他表中搜索字段时出现错误。 这是我的行动
def searchResults ={
if (request.method == 'POST') {
def criteria = Incident.createCriteria()
def results = criteria {
and {
like('status', '%' + params.status + '%')
like('severity', '%' + params.severity + '%')
assignmentGroup {
like('groupId', '%' + params.assignmentGroup + '%')
}
}
}
render(view:'list', model:[ incidentInstanceList: results ])
}
这是我的观点,我让用户选择值:
<g:form action="searchResults" controller="incident">
<div class="dialog">
<table>
<tbody>
<tr class="prop">
<td valign="top" class="name">
<label for="status"><g:message code="incident.status.label" default="Status" /></label>
</td>
<td valign="top" class="value ${hasErrors(bean: incidentInstance, field: 'status', 'errors')}">
<g:select name="status" from="${incidentInstance.constraints.status.inList}"
value="${incidentInstance?.status}" valueMessagePrefix="incident.status" />
</td>
</tr>
<tr class="prop">
<td valign="top" class="name">
<label for="severity"><g:message code="incident.severity.label" default="Severity" /></label>
</td>
<td valign="top" class="value ${hasErrors(bean: incidentInstance, field: 'severity', 'errors')}">
<g:select name="severity" from="${incidentInstance.constraints.severity.inList}"
value="${incidentInstance?.severity}" valueMessagePrefix="incident.severity" />
</td>
</tr>
<tr class="prop">
<td valign="top" class="name">
<label for="assignmentGroup"><g:message code="incident.assignmentGroup.label"
default="Assignment Group" /></label>
</td>
<td valign="top"
class="value ${hasErrors(bean: incidentInstance, field: 'assignmentGroup', 'errors')}">
<g:select id="groupSelect" name="assignmentGroup.id" from="${app.Usergroup.list()}" optionKey="id"
value="" />
</td>
</tr>
</tbody>
</table>
</div>
<div class="buttons">
<span class="button"><g:submitButton name="searchResults" class="searchResults" value="searchResults" /></span>
</div>
</g:form>
对于前两个值,它工作正常。但是assignmentGroup
出现了错误。
Error 500: Executing action [searchResults] of controller [app.IncidentController] caused exception:
IllegalArgumentException occurred calling getter of app.Usergroup.id
事件类:
package app
class Incident {
Usergroup assignmentGroup
User assignId
String severity
String status
static constraints = {
servity(inList:["low","high"])
status(inList:["Open","Closed","WIP"])
createdOn()
assignmentGroup()
}
}
用户组类:
package app
class Usergroup {
String groupId
static hasMany = [members : User]
static belongsTo = User
static mapping = {
table "group_"
}
static constraints = {
groupId(blank:false)
}
String toString (){ groupId }
}
答案 0 :(得分:0)
您是否尝试过类似的标准:
def results = criteria {
and {
like('status', '%' + params.status + '%')
like('severity', '%' + params.severity + '%')
assignmentGroup {
like('groupId', '%' + params.assignmentGroup + '%')
}
}
}
答案 1 :(得分:0)
我认为问题在于你对assignmentGroup使用'like'。我会 尝试类似......
def results = criteria {
like('status', '%' + params.status + '%')
like('servity', '%' + params.servity + '%')
eq('assignmentGroup', params.assignmentGroup)
}
基督教