Groovy:意外标记“:” [英] Groovy: Unexpected token ":"

查看:182
本文介绍了Groovy:意外标记“:”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  EPRole验证器:{EPRole r,EPUserEPRole ur  - > 
if(ur.EPUser == null)return
boolean existing = false
EPUserEPRole.withNewSession {
existing = EPUserEPRole.exists(ur.EPUser.id,r.id)
}
if(existing){
return'userRole.exists'
}
}

当我尝试编译代码时,得到 82:意外标记:validator @ line 82,第10列。



我是groovy的新手,所以任何帮助表示赞赏。

解决方案

您应该将适当类型和名称的属性添加到类中。第一个字母大写用于类(或通常的类型)。所以应该在你的 EPUserEPRole 这样一个属性中:

  EPRole epRole 

然后为 epRole 添加验证器。注意这个例子。

上面的代码会混淆groovy解析器,定义验证器类型 EPRole 后面跟着一个,因此这个错误(或者它会尝试用地图调用EPRole方法,具体取决于上下文)。

I have this auto generated lines of codes:

EPRole validator: { EPRole r, EPUserEPRole ur ->
            if (ur.EPUser == null) return
            boolean existing = false
            EPUserEPRole.withNewSession {
                existing = EPUserEPRole.exists(ur.EPUser.id, r.id)
            }
            if (existing) {
                return 'userRole.exists'
            }
        }

When I try to compile the code I get 82: unexpected token: validator @ line 82, column 10.

I am new in groovy so any help is appreciated.

解决方案

You should add your properties with the proper type and name to the class. First letter uppercase is for classes (or types in general). So there should be in your EPUserEPRole a property like this:

EPRole epRole

Then add the validator for epRole. Pay attention to the case.

Above code would confuse the groovy parser into defining a property validator of type EPRole followed by a :, hence the error (or else it would try to call the method EPRole with the map, depending on context).

这篇关于Groovy:意外标记“:”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆