就像在 stackoverflow 中一样,如果我强制将错误字符放在 URL 中的 id 位置,它会将您重定向到页面错误。我想知道 Grails 是否有某种防止 id 的插件,例如:“123$#3”或一种简单的方法,因为我有很多操作并执行类似下面的操作,这似乎不是最好的方法:
def find = {
def val = OwnStringUtilsClass.verify(params.id)
val ? Book.get(val) : response.sendError(404)
}
最佳答案
您可以在 grails-app/conf/UrlMappings.groovy
中使用以下内容:
"/$controller/$action?/$id?"{
constraints {
id(matches:/\d*/)
}
}
这将确保 id
是数字。
关于url - 防止 url 上的错误请求 "ids"的 Grails 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2110459/