gpt4 book ai didi

grails - 从grails过滤器DSL内部访问常量

转载 作者:行者123 更新时间:2023-12-02 15:36:04 25 4
gpt4 key购买 nike

在这里,我只是想对我需要的字符串键进行干燥处理,但这是唯一的
工作是将字符串直接放入分配中: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")
}
}
}
}
}

最佳答案

将其设置为static或更好的public final static,例如:

class RequestStopwatchFilters {

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

并将其用作:
RequestStopwatchFilters.REQ_KEY    

关于grails - 从grails过滤器DSL内部访问常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10260939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com