Controller 类
class EntidadController {
def index(){
def entidades = Entidad.list()
[entidades:entidades]
render(view:"index")
for (x in entidades)
{
print(x.nombreEntidad)
}
}
}
域类
class Entidad {
String nombreEntidad
int porcentaje
static hasOne = [kiosko: Kiosko]
static belongsTo = [adminCreador: Administrador,entidadSuperior: Entidad]
static hasMany = [adminEntidad: Administrador, entidadesInferiores: Entidad]
static constraints = {
kiosko nullable:true
nombreEntidad nullable : false
adminCreador nullable : true
adminEntidad nullable : true
entidadSuperior nullable : true
entidadesInferiores nullable : true
}
}
在gsp中查看
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<p>test</p>
<div controller="entidadController">
<g:each in="${entidades}" var="x">
<tr>
<td>${x.id}</td>
</tr>
</g:each>
</div>
</body>
</html>
我认为代码很好,但我不知道为什么在g:each标签上不显示任何内容,我尝试在gsp页面中使用静态数组,并且每个g都起作用,并且我在控制台上打印,数组“entidades”上有对象,就像我的 View 无法从 Controller 读取数据
最佳答案
也许这样的渲染语句:
render(view:'index', model:[entidades: entidades])
关于grails - G:每个都不显示任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38898612/