function - Grails域功能不起作用

标签 function grails intellij-idea

我的问题似乎很简单,但自昨天下午以来一直困扰我。我的域类功能不起作用(保存和检索记录)。尽管使用intellij Idea,自动完成仍会检测域字段,因此,如果在声明对象后键入“myDomain.”,则自动完成仍会建议域属性。无论如何,这就是我得到的:

Controller :

def update(){
    switch(request.getMethod()){
         case 'POST':
             if(params.fire == 'true'){
                 def oldClients = Clients.findAll() /* This is where it breaks. Also 
                 note that all other methods of retrieving data doesn't work either,
                 as well as trying to create and save new records. */
             }
             break
    }
}

域:
// I shortened the domain coz the original has a buttload of fields.
class Clients {
    String CClientId
    String CFirstName
    String CSurname
    String CEmail

    static mapping = {
        id name: "CClientId", generator: "assigned"
        version false
        datasource "dataSourceOld"
        cache usage: 'read-only'
    }

    static constraints = {
        CClientId(maxSize: 12)
        CFirstName(nullable: true, maxSize: 5)
        CSurname(maxSize: 30)
        CEmail(maxSize: 30)
    }
}

还有一点需要注意的是,当我尝试以另一种方式声明域的约束时,即CClientId maxSize: 12而不是上面的声明方式,我在cannot resolve symbol上收到CClientId错误,在';', '}' or new line expected之后得到冒号上的maxSize错误,

这是我尝试运行更新操作时遇到的错误:
.Error 
|
2016-06-28 09:42:02,741 [http-bio-7070-exec-10] ERROR errors.GrailsExceptionResolver  - MissingMethodException occurred when processing request: [POST] /oneyeargift/adminhome/updateAbases - parameters:
fire: true
No signature of method: unipoint.oyg.domain.old.ClientsOyg.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure). Stacktrace follows:
Message: No signature of method: unipoint.oyg.domain.old.ClientsOyg.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
    Line | Method
->>   -2 | newInstance0                    in sun.reflect.NativeConstructorAccessorImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     39 | newInstance                     in     ''
|     27 | newInstance . . . . . . . . . . in sun.reflect.DelegatingConstructorAccessorImpl
|    513 | newInstance                     in java.lang.reflect.Constructor
|    991 | jlrConstructorNewInstance . . . in org.springsource.loaded.ri.ReflectiveInterceptor
|     77 | invoke                          in org.codehaus.groovy.reflection.CachedConstructor
|     71 | doConstructorInvoke . . . . . . in     ''
|     42 | callConstructor                 in org.codehaus.groovy.runtime.callsite.ConstructorSite
|     57 | defaultCallConstructor . . . .  in org.codehaus.groovy.runtime.callsite.CallSiteArray
|    182 | callConstructor                 in org.codehaus.groovy.runtime.callsite.AbstractCallSite
|    194 | callConstructor . . . . . . . . in     ''
|     -1 | findAll                         in unipoint.oyg.domain.old.ClientsOyg$$EPpP6s0O
|     45 | defaultCall . . . . . . . . . . in org.codehaus.groovy.runtime.callsite.CallSiteArray
|    108 | call                            in org.codehaus.groovy.runtime.callsite.AbstractCallSite
|    112 | call . . . . . . . . . . . . .  in     ''
|    880 | updateAbases                    in unipoint.oyg.control.admin.AdminhomeController$$EPpP3IMS
|     -2 | invoke0 . . . . . . . . . . . . in sun.reflect.NativeMethodAccessorImpl
|     39 | invoke                          in     ''
|     25 | invoke . . . . . . . . . . . .  in sun.reflect.DelegatingMethodAccessorImpl
|    597 | invoke                          in java.lang.reflect.Method
|    122 | invoke . . . . . . . . . . . .  in org.springsource.loaded.ri.ReloadedTypeInvoker$2
|   1288 | jlrMethodInvoke                 in org.springsource.loaded.ri.ReflectiveInterceptor
|     69 | invoke . . . . . . . . . . . .  in org.codehaus.groovy.grails.web.servlet.mvc.MixedGrailsControllerHelper
|     -1 | invoke                          in grails.plugin.cache.web.ProxyAwareMixedGrailsControllerHelper
|    348 | handleAction . . . . . . . . .  in org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper
|     -1 | handleAction                    in grails.plugin.cache.web.ProxyAwareMixedGrailsControllerHelper
|    231 | executeAction . . . . . . . . . in org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper
|     -1 | executeAction                   in grails.plugin.cache.web.ProxyAwareMixedGrailsControllerHelper
|    197 | handleURI . . . . . . . . . . . in org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper
|     -1 | handleURI                       in grails.plugin.cache.web.ProxyAwareMixedGrailsControllerHelper
|    118 | handleURI . . . . . . . . . . . in org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper
|     -1 | handleURI                       in grails.plugin.cache.web.ProxyAwareMixedGrailsControllerHelper
|     72 | handleRequest . . . . . . . . . in org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController
|     48 | handle                          in org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter
|    328 | doDispatch . . . . . . . . . .  in org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet
|    852 | doService                       in org.springframework.web.servlet.DispatcherServlet
|    882 | processRequest . . . . . . . .  in org.springframework.web.servlet.FrameworkServlet
|    789 | doPost                          in     ''
|    646 | service . . . . . . . . . . . . in javax.servlet.http.HttpServlet
|    727 | service                         in     ''
|    305 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|    200 | doFilter . . . . . . . . . . .  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     -1 | doFilter                        in grails.plugin.cache.web.filter.ehcache.EhcachePageFragmentCachingFilter
|     63 | doFilter . . . . . . . . . . .  in grails.plugin.cache.web.filter.AbstractFilter
|    346 | invokeDelegate                  in org.springframework.web.filter.DelegatingFilterProxy
|    259 | doFilter . . . . . . . . . . .  in     ''
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|     70 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|     70 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|     70 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|    749 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.ApplicationDispatcher
|    487 | processRequest                  in     ''
|    412 | doForward . . . . . . . . . . . in     ''
|    339 | forward                         in     ''
|    318 | forwardRequestForUrlMappingInfo in org.codehaus.groovy.grails.web.util.WebUtils
|    283 | forwardRequestForUrlMappingInfo in     ''
|    274 | forwardRequestForUrlMappingInfo in     ''
|    203 | doFilterInternal                in org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter
|     76 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|     82 | doFilterInternal                in com.linkedin.grails.profiler.ProfilerFilter
|     76 | doFilter . . . . . . . . . . .  in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|    206 | obtainContent                   in org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter
|    152 | doFilter . . . . . . . . . . .  in     ''
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|     -1 | call                            in javax.servlet.FilterChain$doFilter
|     45 | doFilter . . . . . . . . . . .  in org.grails.plugin.resource.DevModeSanityFilter
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|    369 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    109 | invoke . . . . . . . . . . . .  in org.springframework.security.web.access.intercept.FilterSecurityInterceptor
|     83 | doFilter                        in     ''
|    381 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     97 | doFilter                        in org.springframework.security.web.access.ExceptionTranslationFilter
|    381 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     78 | doFilter                        in org.springframework.security.web.authentication.AnonymousAuthenticationFilter
|    381 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    119 | doFilter                        in org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter
|    381 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     54 | doFilter                        in org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter
|    381 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    187 | doFilter                        in org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
|     40 | doFilter . . . . . . . . . . .  in org.codehaus.groovy.grails.plugins.springsecurity.RequestHolderAuthenticationFilter
|    381 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     79 | doFilter . . . . . . . . . . .  in org.codehaus.groovy.grails.plugins.springsecurity.MutableLogoutFilter
|    381 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|     79 | doFilter . . . . . . . . . . .  in org.springframework.security.web.context.SecurityContextPersistenceFilter
|    381 | doFilter                        in org.springframework.security.web.FilterChainProxy$VirtualFilterChain
|    168 | doFilter . . . . . . . . . . .  in org.springframework.security.web.FilterChainProxy
|    346 | invokeDelegate                  in org.springframework.web.filter.DelegatingFilterProxy
|    259 | doFilter . . . . . . . . . . .  in     ''
|    243 | internalDoFilter                in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter . . . . . . . . . . .  in     ''
|    113 | doFilter                        in io.jdev.miniprofiler.servlet.ProfilingFilter
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|     69 | doFilterInternal . . . . . . .  in org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter
|     76 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|     66 | doFilterInternal . . . . . . .  in org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter
|     76 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|     88 | doFilterInternal . . . . . . .  in org.springframework.web.filter.CharacterEncodingFilter
|     76 | doFilter                        in org.springframework.web.filter.OncePerRequestFilter
|    346 | invokeDelegate . . . . . . . .  in org.springframework.web.filter.DelegatingFilterProxy
|    259 | doFilter                        in     ''
|    243 | internalDoFilter . . . . . . .  in org.apache.catalina.core.ApplicationFilterChain
|    210 | doFilter                        in     ''
|    222 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.StandardWrapperValve
|    123 | invoke                          in org.apache.catalina.core.StandardContextValve
|    171 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.StandardHostValve
|     99 | invoke                          in org.apache.catalina.valves.ErrorReportValve
|    118 | invoke . . . . . . . . . . . .  in org.apache.catalina.core.StandardEngineValve
|    408 | service                         in org.apache.catalina.connector.CoyoteAdapter
|   1023 | process . . . . . . . . . . . . in org.apache.coyote.http11.AbstractHttp11Processor
|    589 | process                         in org.apache.coyote.AbstractProtocol$AbstractConnectionHandler
|    312 | run . . . . . . . . . . . . . . in org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor
|    895 | runTask                         in java.util.concurrent.ThreadPoolExecutor$Worker
|    918 | run . . . . . . . . . . . . . . in     ''
^    662 | run                             in java.lang.Thread

任何帮助将非常感激。

最佳答案

我认为问题是由于您命名域类的属性的方式引起的。
您是否尝试过以下操作?

class Clients {
    String cClientId
    String cFirstName
    String cSurname
    String cEmail

    static mapping = {
        id name: "cClientId", generator: "assigned"
        version false
        datasource "dataSourceOld"
        cache usage: 'read-only'
    }

    static constraints = {
        cClientId(maxSize: 12)
        cFirstName(nullable: true, maxSize: 5)
        cSurname(maxSize: 30)
        cEmail(maxSize: 30)
    }
}

因此,如果您声明约束如下:
static constraints = {
    cClientId maxSize: 12
    cFirstName nullable: true, maxSize: 5
    cSurname maxSize: 30
    cEmail maxSize: 30
}

其作品 ;)

关于function - Grails域功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38070255/

相关文章:

r - 如何让这个函数与r中的管道一起使用?

grails - 多项目中的插件在Grails 3.2.11上失败

unit-testing - 如何为这个 Controller 方法编写单元测试?

android - 将图片目录导入到Android Studio中的drawable资源中

vim - intellij 中的 ideavim 是否有转到下一个错误的快捷方式?

python - 无法在 IntelliJ IDEA 中创建新的 GAE (Python) 项目

PHP 更改为 mysqli。 mysqli_connection 不是全局的吗?

c++ - 将未知大小的二维数组传递给 C++ 中的函数

c - 一个包含结构体的函数,该结构体在以下函数中声明?

hibernate - 没有GORM的轻质GRAILS