[英]Grails how to do multiple search queries
I have this from my controller: 我从我的控制器那里得到了这个:
def purchaseRequestList = PurchaseRequest.createCriteria().list (params) {
if ( params.query) {
ilike('requestBy', "%${params.query}%")
}
Above is a snippet from my list method 上面是我的列表方法的摘录
It can only do one search by the params requestBy 它只能按参数请求进行一次搜索
Then i do this in my gsp 然后我在我的gsp中执行此操作
<g:form action="listPurchaseRequest" method="GET">
<g:textField id="search" class="pull-right" name="query" value="${params.query}" placeholder=" Search"/>
</g:form>
Now i added a new param of requestNumber 现在我添加了一个requestNumber的新参数
How do i do two or more searches? 如何进行两次或更多次搜索?
I'll take a guess that you want to use the single param query
to search against multiple fields in the domain class PurchaseRequest
. 我会猜测您要使用单个参数query
来搜索域类PurchaseRequest
中的多个字段。 This could be done like: 可以这样完成:
def purchaseRequestList = PurchaseRequest.findAllByRequestByLikeOrRequestNumberLike("%${params.query}%", "%${params.query}%", params)
See the Dynamic Finders section of the Grails docs . 请参阅Grails文档的Dynamic Finders部分 。
The other alternative could be nesting ilike for different params of the model using or{}: 另一种选择是使用or {}为模型的不同参数嵌套ilike:
def users = User.createCriteria().list(params) {
if (params.query) {
or {
ilike("fullName", "%${params.query}%")
ilike("email", "%${params.query}%")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.