Adding UrlMapping constraints to a VERB-mapped url

2019-08-27 19:58发布

问题:

Is it possible to add constraints to HTTP verb-matched Url Mappings?

Here's my current definition:

    "/a/$param1/b" {
        controller = "a"
        action = [GET: 'method1',
                  POST: 'method2'
                 ]
    }

回答1:

Sure, this seems to work:

"/rest/$controller/$id?"(parseRequest:true) {
        action = [GET: "show", POST: "update", PUT:"save", DELETE:"delete"]
        constraints { id(matches:/[0-9]+/) }
    }