gpt4 book ai didi

grails - 呈现 View ,但gsp中没有对象

转载 作者:行者123 更新时间:2023-12-02 15:17:02 26 4
gpt4 key购买 nike

我尝试渲染一个 View ,该 View 工作正常,但似乎无法获得传递给它的模型对象。我不知道原因,因为根据所有手册和示例,这应该非常简单。

模型对象

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>

但我反而得到了
object not found

关于我错过的基本知识有什么想法吗?

最佳答案

您具有以下内容:

def doFullRace(Race race) {
render (view: 'raceProgress', model: [race: race])
}

如果满足以下所有条件,则 race成为 null的方法之一:
  • Race是域类
  • 提交给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".

    关于grails - 呈现 View ,但gsp中没有对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54653467/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com