【问题标题】:render method not working in Grails渲染方法在 Grails 中不起作用
【发布时间】:2010-11-19 23:45:24
【问题描述】:

我刚开始在行动书中使用 grails。

grails create-app制作的新应用

然后书上说在 QuoteController.groovy 中有以下代码

class QuoteController {
    def index = {}
    def home = {
        render= "<h1>Real programmers do not each Quiche</h1>"
    }
}

现在当我浏览到页面 http://localhost:8080/qotd/quote/home 时,我收到以下错误:

Error 500: groovy.lang.MissingPropertyException: No such property: render for class: QuoteController
Servlet: grails
URI: /qotd/grails/quote/home.dispatch
Exception Message: No such property: render for class: QuoteController
Caused by: groovy.lang.MissingPropertyException: No such property: render for class: QuoteController
Class: Unknown
At Line: [-1]
Code Snippet:

似乎“渲染”不是有效属性?有什么想法我可能做错了吗? 我正在使用 Grails 1.1.1

【问题讨论】:

    标签: grails


    【解决方案1】:

    ....一定是我收工的时候了..书上说要编写以下代码:

    class QuoteController {
        def index = {}
        def home = {
            render "<h1>Real programmers do not each Quiche</h1>"
        }
    }
    

    而不是 render = "..."

    【讨论】:

    • 呵呵,初学者程序员的经典错误 =) 鉴于 groovy 的动态特性,您需要时刻注意拼写错误。
    • 这里的小提示,只是为了让您知道实际发生了什么:render 是一个带有一个字符串参数的方法(尽管还有其他重载)。在 Groovy 中,您可以省略带有单个参数的方法的括号。
    • 实际上,更准确地说,在 Groovy 中,您可以省略括号“如果至少有一个参数并且没有歧义”。见groovy.codehaus.org/Statements
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多