0

在这里,我只是想对我需要的字符串键进行干燥,但唯一有效的是将字符串直接放入分配中:request['RequestStopwatch.start'] = System.currentTimeMillis().

任何指针?

class RequestStopwatchFilters {

    def REQ_KEY = 'RequestStopwatch.start'

    def filters = {
        all(controller:'*', action:'*') {

            before = {

                log.debug(""+System.currentTimeMillis() + " " + request)
                // NULL pointer exception on REQ_KEY here:
                request[REQ_KEY] = System.currentTimeMillis()
            }
            after = { Map model ->
                if (log.isDebugEnabled()) {
                    // NULL pointer exception on REQ_KEY here:
                    log.debug("Stopped request before view at " + (System.currentTimeMillis() - request[REQ_KEY]) + "ms")
                }
            }
            afterView = { Exception e ->
                if (log.isDebugEnabled()) {
                    // NULL pointer exception on REQ_KEY here:
                    log.debug("Stopped request at " + (System.currentTimeMillis() - request[REQ_KEY]) + "ms")
                }
            }
        }
    }
}
4

1 回答 1

1

使其成为static或更好public final static,例如:

class RequestStopwatchFilters {

    public final static String REQ_KEY = 'RequestStopwatch.start'
}

并在任何地方使用它:

RequestStopwatchFilters.REQ_KEY    
于 2012-04-21T17:29:58.893 回答