一直试图从不同的程序中获取价值,但没有成功。
控制器:
def list(){
Student stud = new Student()
def listStudents = stud.executeQuery("from Student")
listStudents.each{ lisStud->
println "email = ${lisStud.email}"
render view:"/layouts/listOFstudents"
}
表格
<table>
<tr>
<g:each in="${lisStud}">
<td>${lisStud.email}</td>
</g:each>
答案 0 :(得分:1)
class HelloController {
def index() {
def list = []
list << new Person(firstName: 'John', lastName:'Doe', age:50)
list << new Person(firstName: 'Jane', lastName:'Smith', age:45)
list << new Person(firstName: 'Sam', lastName:'Robinson', age:47)
[ list:list ]
}
}
只是不要将页面渲染到任何其他页面然后索引
答案 1 :(得分:1)
控制器:
def list(){
Student stud = new Student()
def listStudents = stud.executeQuery("from Student")
def displayStudentList = []
listStudents.each{ lisStud->
println "email = ${lisStud.email}"
displayStudentList += it
}
[displayStudentList : displayStudentList]
}
查看:
的list.gsp
<g:each in="${displayStudentList}" var="lisStud">
<td>${lisStud.email}</td>
</g:each>