I have a domain-class called option. There is an attribute called name.

The names are like:

abc.1
abc.2
xxx.1
xxx.2
xxx.3

I want all options that start with abc. Normally I use Options.findByName("xyz") But i want all that start with abc. So in that example:

abc.1
abc.2

The regex could be /abc(.).*/

But where I have to write that?

有帮助吗?

解决方案

If you need only simple "startsWith" condition, you can use like:

  Options.findAllByNameLike("abc%")

其他提示

Consider using colusers inside the findAll /findByName method Have u tried this one ?

Example

def result = ["abc1", "acb2", "abc3"].findAll { it ==~ /abc.*/ }

or in your case

def result = Options.findByName { it ==~ /abc.*/ }

Or refer this link for bunch of reference on regular expression http://groovy.codehaus.org/Regular+Expressions

Cheers!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top