gpt4 book ai didi

grails - 在grails中的多个表中搜索多个值的最佳方法是哪种?插件还是动态查找器?

转载 作者:行者123 更新时间:2023-12-02 14:55:20 24 4
gpt4 key购买 nike

我使用动态查找器进行搜索,但是当我搜索其他表中的字段时出现错误。
这是我的行动

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 ])
}

这是我让用户选择值的 View :
   <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 }
}

最佳答案

您是否尝试过类似这样的条件:

def results = criteria {
and {
like('status', '%' + params.status + '%')
like('severity', '%' + params.severity + '%')
assignmentGroup {
like('groupId', '%' + params.assignmentGroup + '%')
}
}
}

关于grails - 在grails中的多个表中搜索多个值的最佳方法是哪种?插件还是动态查找器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6991318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com