考虑 Grails 2.1.1 中的以下操作
class ActionController {
static allowedMethods = [submit: 'POST']
def submit() {
render([ok: true, data: request.JSON] as JSON)
}
}
以下命令:
curl -X POST http://localhost:8080/backoffice/action/submit \
-H 'Content-Type: application/json' \
-d '{"foo":"bar"}'
返回
{"ok" : true, "data" : {"foo" : "bar"}}
但是如果在 json 中有一个名为 的元素action
,那么 Grails 将尝试找到一个名称等于该元素值的动作!
例如 :
curl -X POST http://localhost:8080/backoffice/action/submit \
-H 'Content-Type: application/json' \
-d '{"foo":"bar","action":"bar"}'
结果导致404 错误,因为 grails 正在尝试查找 uri /action/bar.dispatch
!
我怎样才能禁用这个奇怪的功能?
我的UrlMappings.groovy
:
static mappings = {
"/$controller/$action?/$id?"(parseRequest: true){
constraints {
// apply constraints here
}
}
行为是否是由于parseRequest=true
?我使用此参数能够使用来自 json 的 CommandObject。