我试图按照Grails In Action(http://www.manning.com/gsmith2/GiA2E_meap_ch01.pdf)中的分步说明进行操作,并在第1.5.1节中解释脚手架。 21-23似乎不适合我。我建议在QuoteController.groovy
中加上static scaffold = true
。那时 Grails的运行程序,当我前往localhost:8080/qotd/quote/list
我得到一个404错误(而不是图1.11中的PDF格式),如下所示:在Grails中使用脚手架时出现404错误
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
:
package qotd class QuoteController { static scaffold = true def index() { redirect(action: "home") } def home() { render "Real Programmers do not eat Quiche" } def random() { def allQuotes = Quote.list() def randomQuote def n = allQuotes.size() if (n > 0){ def randomIdx = new Random().nextInt(n) randomQuote = allQuotes[randomIdx] } else{ String str = "Real Programmers Don't Eat Quiche" + n randomQuote = new Quote(author: "Anonymous", content: str) } [quote: randomQuote] } }
但是,去localhost:8080/qotd/quote/create
工作正常(匹配pdf中的图1.12),我可以创建一个新的报价。
我使用的版本是:
应用程序版本: 0.1
的Grails版本: 2.3.1
Groovy的版本: 2.1.8
JVM版本: 1.7.0_45
这是Grails中的错误还是我缺少什么?
我是Groovy和Grails的新手,任何帮助将不胜感激。 谢谢!
非常感谢你为眼前的FE edback(对于像我这样的新手来说真的很有帮助)。我也曾在Git上提过这个问题,解决方案就是你刚才提到的。以下是面向相同问题的其他人的Git链接https://github.com/GrailsInAction/graina2/issues/54 – tikka