我試圖按照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