从grails项目执行(在控制台中):
import vine.*
import grails.converters.JSON
s = Stem.makeStem([name: "nameValue", description: "Description value"], "24601")
println s as JSON
生成:
groovy.lang.MissingMethodException:没有方法签名:vine.Stem.makeStem()适用于参数类型:(java.util.LinkedHashMap,java.lang.String)values:[[name:nameValue,description:描述值],BR-459] 可能的解决方案: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) 在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
}
我最初使用地图h进行了def,但这也没有用。
有什么想法吗?
答案 0 :(得分:1)
假设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
{
...
}