【发布时间】:2015-05-18 14:30:53
【问题描述】:
我正在尝试实现一个过滤器,在进入 GSP 页面之前应该在某些情况下调用该过滤器。由于 URL 在我希望它发生的实例和我不希望它发生的实例之间没有太大差异,我认为最好的方法是创建一个什么都不做的方法(里面有一个 print 语句) - 但可以在我希望过滤操作发生时简单地调用。
我都试过了:
def hello(){
print "hello"
}
和
def hello = {
print "hello"
}
只需添加
即可调用它们hello()
在相关点
我的过滤器的开头如下:
import uui.FormattingService
class TimeFormatterFilters {
def FormattingService formattingService
def filters = {
someFilter(controller: 'userProfile', action: 'hello') {
before = {
print "filter action taking place"
对于 UserProfileController 中的任一新方法,我都没有在过滤器中看到 print 语句,但是如果我将过滤器的操作交换为 'index',我会看到过滤器中的打印被调用。
【问题讨论】:
标签: grails filter grails-filters