我正在尝试使用SQL返回的某些行来填充grails select但由于某种原因它无效。我有以下代码:
控制器:
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)]
}
}
GSP选择:
<g:select name="insuranceSemesterVerified" from="${terms}" required="" value="${clinicalRequirementsInstance?.insuranceSemesterVerified}" valueMessagePrefix="clinicalRequirements.insuranceSemesterVerified"/>
我很难过。希望有人可以指出我的错误。我已经在其他地方验证了对数据库的查询。
答案 0 :(得分:0)
控制器仅返回最后一行(除非你在某处放置return
语句),所以将你的最后一行更改为:
[clinicalRequirementsInstance: new ClinicalRequirements(params), terms: terms]