如何在HQL/GORM中表达"动态列表中的值"?

xcu*_*cut 6 grails hql grails-orm

对于grails应用程序,我需要找到一个对象列表,其中"attr"是动态字符串列表中的一个.实际的HQL查询更复杂,但我需要帮助的是这个:

def result = MyObject.executeQuery("select o from MyObject as o where o.attr in :list",
    [list: aListOfStrings])
Run Code Online (Sandbox Code Playgroud)

这显然不是正确的语法,Grails将它作为"意外令牌"抛回给我,作为:list参数.

这在HQL中是否可行?我并不特别想在代码库的这一部分使用Criteria.

Bur*_*ith 19

Put:parens中的列表:

def result = MyObject.executeQuery(
    "select o from MyObject as o where o.attr in (:list)",
    [list: aListOfStrings])
Run Code Online (Sandbox Code Playgroud)

  • 伯特4总统! (4认同)