本文介绍了如何从Grails中的UrlMapping中排除特定关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Grails中使用以下URL映射: / $ id{
controller =user
action =show
}
可映射网址,例如 mydomain.com/someusername
如何将约束附加到url映射以排除诸如login,logout等关键字
即,
mydomain.com/someusername应该路由到mydomain.com/user/show/someusername,
mydomain.com/login不应路由至mydomain.com/user/show/login。
解决方案
您可以使用这个映射的约束:
/ $ id{
controller =user
action =show
constraints {
//在url映射中为$ id添加一个验证器
id(validator:{
return!(it in ['login','logout'])
})
}
}
I use the following url mapping in Grails:
"/$id"{
controller = "user"
action = "show"
}
to map urls like mydomain.com/someusername
How do I attach constrains to the url mapping to exclude keywords like "login", "logout",...
I.e., mydomain.com/someusername should route to mydomain.com/user/show/someusername,mydomain.com/login should not route to mydomain.com/user/show/login.
解决方案
You can use contrainsts for this mapping:
"/$id"{
controller = "user"
action = "show"
constraints {
//add a validator for $id from url mapping
id(validator: {
return !(it in ['login', 'logout'])
})
}
}
这篇关于如何从Grails中的UrlMapping中排除特定关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!