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

标签 grails render gsp

我尝试渲染一个 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/

    相关文章:

    web-services - 用grails调用Web Services的异常

    jquery - 将 'id'插入具有外键(HQL)的字段中

    javascript - Rails 3.2 + jQuery + js.erb 中的部分渲染 = HTML 元素损坏

    grails - 仅在构建WAR时才检测到Grails标记未关闭

    grails - 将数字格式化为货币

    java - Grails - 导入 jsch 结果为 "package com.jcraft.jsch does not exist"

    grails - 如何在 Grails 中保存或更新?

    javascript - 调整大小的 Canvas - 保持最大宽度或高度而不拉伸(stretch)/填充

    html - 浏览器是否必须使用 DOM 来呈现 HTML 页面?

    spring - Grails Spring安全性插件-自定义登录和注销URL, Controller 和GSP