Question

i can do this:

def criteria = Category.createCriteria();
def results = criteria.list{ 
                          like('categoryName', "%abc%") or
                          like('categoryName', "%qwe%") 

                        };

but how i do it for unknown number of string values? i would like do something like:

def results = criteria.list{  
for (str in strList){
like('categoryName', str) or
                          }
                        };

but ofcourse it doesnt work.

Was it helpful?

Solution

Use or { }:

def criteria = Category.createCriteria()
def results = criteria.list {
    or {
        strList.each { str ->
            like('categoryName', "%${str}%")
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top