简体   繁体   中英

How to search using a domain class instance?

I have a domain class User with all the instances like

[User : 1, User: 2, User : 3, User:4, User: 5, User: 6, User: 7, ...]

and an instance list userInstanceList with only a few objects, say

[User : 3, User:4]

My search term is in User : 4 and also in some other objects in User . When I search using

User.search(userInstanceList, searchTerm)

it returns all the objects in User with the searchTerm . How can I search objects only in userInstanceList

If you want to restrict the search to only the things in the userInstanceList, you should be able to just use the in clause when searching.

User.findAll { 
   searchTerm && id in userInstanceList*.id
}

or

User.withCriteria {
    searchTerm
    inList id, userInstanceList*.id
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM