2012-07-03 75 views
0

我正在嘗試使用Grails實現以下SQL。Grails - 如何將值列表傳遞給域類

「Select * from table1 where col1=’COL1’ and col2 in(‘COL2_1’,’COL2_2’,….) and col3=1」 

我可以得到COL2地圖,不知道如何將這個地圖傳遞到表1域

我嘗試這樣的事情

table1.findAllWhere(col1:'COL1', col2 :modelMap.COl2, col3:1) 

這是返回null。

我很欣賞這個

感謝所有幫助 巴拉

回答

1

您可以在這幾乎是一個直接的翻譯使用HQL此:

Map params = [col1: 'COL1', col2List: ['COL2_1', 'COL2_2', 'COL2_3'], col3: '1'] 

TableOne.executeQuery(""" 
    select t1 
    from TableOne t1 
    where t1.col1 = :col1 and t1.col2 in (:col2List) and t1.col3 = :col3 
""", params)