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
<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
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
. This could be done like:
def purchaseRequestList = PurchaseRequest.findAllByRequestByLikeOrRequestNumberLike("%${params.query}%", "%${params.query}%", params)
The other alternative could be nesting ilike for different params of the model using or{}:
def users = User.createCriteria().list(params) {
if (params.query) {
or {
ilike("fullName", "%${params.query}%")
ilike("email", "%${params.query}%")
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.