1

我正在尝试使用从 SQL 返回的一些行填充 grails 选择,但由于某种原因它无法正常工作。我有以下代码:

控制器:

import groovy.sql.Sql

class ClinicalRequirementsController {

static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

def dataSource //injection of dataSource 

def create() {

     def db = new Sql(dataSource)

     def terms = db.rows("""SELECT stvterm_code
     FROM stvterm
     WHERE stvterm_fa_proc_yr = (SELECT stvterm_fa_proc_yr
     FROM stvterm, current_term
     WHERE stvterm_code = current_term.cur_term)
     ORDER BY stvterm_code ASC""")

     [terms: terms]

     db.close()

     [clinicalRequirementsInstance: new ClinicalRequirements(params)]
   }
}

普惠制选择:

<g:select name="insuranceSemesterVerified" from="${terms}" required=""   value="${clinicalRequirementsInstance?.insuranceSemesterVerified}" valueMessagePrefix="clinicalRequirements.insuranceSemesterVerified"/>

我很困惑。希望有人可以指出我出了什么问题。我已经在别处验证了针对数据库的查询。

4

1 回答 1

0

控制器只返回最后一行(除非你return在某处放了一条语句),所以把你的最后一行改成这样:

[clinicalRequirementsInstance: new ClinicalRequirements(params), terms: terms]
于 2012-10-26T22:13:40.603 回答