gpt4 book ai didi

grails - 如果语句简单(?)

转载 作者:行者123 更新时间:2023-12-02 15:00:31 25 4
gpt4 key购买 nike

因此,尝试做某事(我认为应该很简单)
在代码中进一步设置一个值,然后执行if语句检查我设置的值。
设置变量的代码段。复制在下面

if ( params.headers == null) {
def headline="1"
render ("Starting to read on line 1<BR>")
} else {
def headline="0"
render ("Skipping line 1<BR>")
}

然后在 Controller 中往下走一点,我执行以下操作
if ( headline == "0") {
render "Skipped line for ${fields[0]}"
headline = "1"
} else {

每当我运行此命令时,我都会收到以下错误消息”
No such property: headline for class: regmap.CountryuploadController. Stacktrace follows:
Message: No such property: headline for class: regmap.CountryuploadController
Line | Method
->> 25 | doCall in regmap.CountryuploadController$_loadcsv_closure1$$EOrLxdfM
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 34 | eachLine in org.grails.plugins.csv.CSVReaderUtils
| 47 | eachLine in ''
| 140 | doCall in CsvGrailsPlugin$_closure4_closure12
| 22 | loadcsv . in regmap.CountryuploadController$$EOrLxdfM
| 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread

有任何想法吗?
很明显我错过了一些东西,甚至我试图互相追逐。

最佳答案

由于您在headlineif块内声明了else变量,因此其范围仅限于这些块,这就是为什么稍后尝试引用它时会出错的原因。您想要这样的东西:

def headline
if ( params.headers == null) {
headline="1"
render ("Starting to read on line 1<BR>")
} else {
headline="0"
render ("Skipping line 1<BR>")
}

关于grails - 如果语句简单(?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26122810/

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