我试图按照 Grails In Action ( http://www.manning.com/gsmith2/GiA2E_meap_ch01.pdf )中的分步说明,以及第 1.5.1 节中解释的脚手架,第 1 页。21-23 似乎对我不起作用。
我按照建议添加static scaffold = true了。QuoteController.groovy然后grails run-app,当我前往时,我得到一个 404 错误(而不是 pdf 中的图 1.11),如下所示:localhost:8080/qotd/quote/list
HTTP Status 404 - /qotd/quote/list
type Status report
message /qotd/quote/list
description The requested resource is not available.
Apache Tomcat/7.0.42
这是QuoteController.groovy:
包 qtd
类报价控制器 {
静态脚手架 = true
定义索引(){
重定向(动作:“家”)
}
默认主页(){
渲染“真正的程序员不吃乳蛋饼”
}
定义随机(){
def allQuotes = Quote.list()
def 随机报价
def n = allQuotes.size()
如果 (n > 0){
def randomIdx = new Random().nextInt(n)
randomQuote = allQuotes[randomIdx]
} 别的{
String str = "真正的程序员不吃乳蛋饼" + n
randomQuote = new Quote(作者:“匿名”,
内容:str)
}
[引用:随机引用]
}
}
但是,一切正常(与 pdf 中的图 1.12 匹配),我可以创建一个新报价。localhost:8080/qotd/quote/create
我使用的版本是:
App 版本: 0.1
Grails 版本: 2.3.1
Groovy 版本: 2.1.8
JVM 版本: 1.7.0_45
这是 Grails 中的错误还是我遗漏了什么?
我是 Groovy 和 Grails 的新手,任何帮助都将不胜感激。谢谢!