2017-03-07 198 views
0

美好的一天,我試圖將所有用戶從我的數據庫添加到列表中並將其打印出來。但問題是我只檢索用戶表的最後記錄。其他人被忽略。這裏是我的代碼sql.eachRow只會將最後一條記錄添加到列表中

table(selectionMode: ListSelectionModel.SINGLE_SELECTION){ 
        sql.eachRow("select * from users"){row-> 
          println row; 
         def staffList = []  
       staffList.add(uname:row.uname,pwd:row.pwd); 

        tableModel(list : staffList){ 
        closureColumn(header:'Username',read:{row1 -> return row1.uname}) 
        closureColumn(header:'Password',read:{row1 -> return row1.pwd}) 


        } 

回答

0

我認爲問題是你已經重新定義循環內的staffList數組。把它移到之前,你可能會有更好的結果。

+0

你好,@Steve Lovell!非常感謝!它確實有效。所以每個閉包都是一個循環。我很抱歉,因爲我在Groovy是一個新手。非常感謝! – IWantToBeAnAnonymous

+0

太好了。如果你可以將其標記爲答案,那將是可愛的。 –

相關問題