grails - Groovy/Grails没有方法签名

标签 grails groovy

从grails项目中执行(在控制台中):
import vine.* import grails.converters.JSON s = Stem.makeStem([name: "nameValue", description: "Description value"], "24601") println s as JSON
产生:

groovy.lang.MissingMethodException: No signature of method: vine.Stem.makeStem() is applicable for argument types: (java.util.LinkedHashMap, java.lang.String) values: [[name:nameValue, description:Description value], BR-459] Possible solutions: makeStem(java.util.LinkedHashMap, java.lang.String) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1075) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)



方法定义:
def makeStem( LinkedHashMap h, String owner)
{
    def s
    if ( h.name && h.description ) {
       s  = new Stem(h)
       def ra = new RoleAssignment(peoples: owner)
       s.addRole(ra)
    }
    return s
}

我最初使用Map h进行了定义,但是那也不起作用。

有任何想法吗?

最佳答案

假设Stem是服务类。

您可以在Grails控制台中执行以下操作

import vine.*
import grails.converters.JSON
def stem= ctx.stem
s = stem.makeStem([name: "nameValue", description: "Description value"], "24601")
println s as JSON

假设Stem是一个域类,
static makeStem( LinkedHashMap h, String owner)   // convert it to a static method
{
    ...
}

关于grails - Groovy/Grails没有方法签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40156472/

相关文章:

twitter-bootstrap - GRAILS-如何在Grails 3.2.9中开始使用Twitter Bootstrap,什么是最好的方法?

grails - 为什么 save() 不保存数据和 save(flush : true) is required?

grails - 与各种Grails应用程序共享Spring Security Core

Groovy 将对象列表转换为逗号分隔的字符串

xml - 如何打印保留命名空间的 groovy 节点?

grails - 可以让 IntelliJ 使用 Grails 包装器吗?

jenkins - 如何将其他 groovy 文件导入到我的 pipeline.groovy 文件中?

java - 正则表达式无法匹配 switch case 模式

正则表达式转义 Groovy 中的特殊字符

grails - 在 Bootstrap.groovy 中设置 Grails 域 ID