gpt4 book ai didi

grails - java.lang.IllegalStateException =混淆新手

转载 作者:行者123 更新时间:2023-12-02 14:02:01 24 4
gpt4 key购买 nike

一个困惑的Grails新手。我目前正在阅读中的教程
一本书(史密斯·莱德布鲁克,《行动中的Grails》,曼宁出版社,第一版)
并陷入第一章!当浏览到本地主机时,我得到
错误消息,请参见下文。本教程将引导我创建一个
每日随机报价应用程序。您可能会怀疑,浏览到
网页给出随机报价(已保存在“Quote”域类中)
每次刷新。

我已经制作了 Controller , View ,布局,域类,所有这些都是
很简单。我想如果没有的话我会得到这些错误
测试数据,但是使用grails控制台向我显示了该数据。尽管
这样,刷新浏览器就会在打开的终端中回显错误。

Quote域类和 Controller 的代码也在下面。一世
想要更改开发环境的配置文件
持久性,因此条目也位于此处。让我知道你是否需要看看
还要别的吗...

有任何想法吗? (使用在Ubuntu 14.04上安装的Grails版本2.4.0。
Grails 1.1的代码)

错误:

URI :/ qotd / quote / random

:java.lang.IllegalStateException

消息:类[qotd.Quote]上的方法在Grails之外使用
应用。如果在使用模拟API的测试环境中运行,或者
引导Grails正确。

Around line 8 of grails-app/controllers/qotd/QuoteController.groovy
6:
7: def random = {
8: def allQuotes = Quote.list()
9: /*def randomQuote
10: if (allQuotes.size() > 0 )
11: {

Trace
Line | Method
->> 9 | doCall in QuoteController.groovy
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 198 | doFilter in PageFragmentCachingFilter.java
| 63 | doFilter in AbstractFilter.java
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread

Controller
package qotd

class QuoteController {

def index = { }

def random = {
def allQuotes = Quote.list()
/*
def randomQuote
if (allQuotes.size() > 0 )
{
def randomIdx = new Random().nextInt(allQuotes.size())
randomQuote = allQuotes[randomIdx]
} else {
randomQuote = new Quote(author: "Anonymous",
content: "Real Programmers Don't eat Quiche")
}
[quote : randomQuote ]
*/

}
}

引用域类
package qotd

class Quote {

String content
String author
Date created = new Date()

static constraints = {
}
}

来自DataSource.groovy的 开发环境
    development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update',
'validate', ''
url =
"jdbc:h2:file:~/h2db/quotedevdb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
}
}

最佳答案

是的,作为grantmcconnaughey注释,您不想将 Controller Action 声明为带有'='符号的闭包。现在建议使用方法。因此,您可以执行以下操作:

def random() {
def allQuotes = Quote.list()
}

要么:
public random() {
def allQuotes = Quote.list()
}

参见 online docs

关于grails - java.lang.IllegalStateException =混淆新手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24016832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com