渲染视图,但 gsp 中没有对象
Rendering view, but no object in gsp
我尝试渲染一个视图,效果很好,但它似乎没有得到我传递给它的模型对象。我无法弄清楚原因,因为根据所有手册和示例,这应该是非常简单的。
模型对象
class Race {
def distance = "1/4 mile"
def racer1
def racer2
}
RaceController
在此处呈现
def doFullRace(Race race) {
render (view: 'raceProgress', model: [race: race])
}
和raceProgress.gsp
应该很容易显示它
<html>
<body>
<div id="raceStart" align="center">
...
<p>${race.racer1} is racing ${race.distance} against ${race.racer2}</p>
</div>
</body>
</html>
但我反而明白了
关于我错过了什么基本的事情有什么想法吗?
您有以下内容:
def doFullRace(Race race) {
render (view: 'raceProgress', model: [race: race])
}
race
成为 null
的方法之一是,如果以下所有条件都为真:
Race
是一个域 class
- 提交给
doFullRace
的请求包含一个名为 id
的请求参数
- 数据库中没有
id
匹配 params.id
的记录
从http://docs.grails.org/3.3.9/guide/theWebLayer.html#commandObjects...
If the command object’s type is that of a domain class and there is an
id request parameter then instead of invoking the domain class
constructor to create a new instance a call will be made to the static
get method on the domain class and the value of the id parameter will
be passed as an argument.
还有...
If the command object’s type is a domain class and there is no id
request parameter or there is an id request parameter and its value is
empty then null will be passed into the controller action unless the
HTTP request method is "POST", in which case a new instance of the
domain class will be created by invoking the domain class constructor.
For all of the cases where the domain class instance is non-null, data
binding is only performed if the HTTP request method is "POST", "PUT"
or "PATCH".
我尝试渲染一个视图,效果很好,但它似乎没有得到我传递给它的模型对象。我无法弄清楚原因,因为根据所有手册和示例,这应该是非常简单的。
模型对象
class Race {
def distance = "1/4 mile"
def racer1
def racer2
}
RaceController
在此处呈现
def doFullRace(Race race) {
render (view: 'raceProgress', model: [race: race])
}
和raceProgress.gsp
应该很容易显示它
<html>
<body>
<div id="raceStart" align="center">
...
<p>${race.racer1} is racing ${race.distance} against ${race.racer2}</p>
</div>
</body>
</html>
但我反而明白了
关于我错过了什么基本的事情有什么想法吗?
您有以下内容:
def doFullRace(Race race) {
render (view: 'raceProgress', model: [race: race])
}
race
成为 null
的方法之一是,如果以下所有条件都为真:
Race
是一个域 class- 提交给
doFullRace
的请求包含一个名为id
的请求参数
- 数据库中没有
id
匹配params.id
的记录
从http://docs.grails.org/3.3.9/guide/theWebLayer.html#commandObjects...
If the command object’s type is that of a domain class and there is an id request parameter then instead of invoking the domain class constructor to create a new instance a call will be made to the static get method on the domain class and the value of the id parameter will be passed as an argument.
还有...
If the command object’s type is a domain class and there is no id request parameter or there is an id request parameter and its value is empty then null will be passed into the controller action unless the HTTP request method is "POST", in which case a new instance of the domain class will be created by invoking the domain class constructor. For all of the cases where the domain class instance is non-null, data binding is only performed if the HTTP request method is "POST", "PUT" or "PATCH".