我有一个过滤器,我希望过滤除了带来登录页面的ONE之外的所有操作。
如果我过滤掉所有具有某些条件的页面,那么甚至LOGIN页面也会被过滤掉,因此当条件未满足时它会卡在infinte循环中(User not Logged IN)。
session.getAttribute(“CurrentEmployeeIds”)它告诉用户是否已登录
我的过滤器:
class LoginFilters {
def filters = {
all(controller:'dashboard', action:'*') {
before = {
if (session.getAttribute("CurrentEmployeeIds")==null) {
redirect(controller:"site",action:"index")
return false
}
}
after = { Map model ->
}
afterView = { Exception e ->
}
}
}
}
我希望以这样的方式进行过滤:它不会过滤controller:"site",action:"index"
此网址并过滤其他所有内容。
提前谢谢。
答案 0 :(得分:11)
您可以反转过滤规则,例如:
def filters = {
allExceptIndex(controller:"site",action:"index",invert:true) {
before = {
}
after = { Map model ->
}
afterView = { Exception e ->
}
}
}
请参阅文档http://grails.org/doc/latest/guide/theWebLayer.html#filters