how to call service from controller in grails

2019-05-05 04:09发布

问题:

I have a service class and i am trying to call the method of the service in my controller as below.

class LogListController {

def ListLogDetails = { 
    println "We are inside List log Details-->"+params
    def logListHelperService
    logListHelperService.getFilePath(params)
}}

Exception Message: Cannot invoke method getFilePath() on null object

what is my mistake there..

回答1:

def logListHelperService

must be declared outside of the ListLogDetails definition

def logListHelperService
def ListLogDetails = { 
    println "We are inside List log Details-->"+params
    logListHelperService.getFilePath(params)
}

should work