Results 1 to 7 of 7

Thread: Using Spring 3 path variables

Threaded View

  1. #1
    Join Date
    Apr 2005
    Posts
    25

    Default Using Spring 3 path variables

    I'm playing with Grails and trying to port an existing Spring 3 app.

    I'm having trouble with @RequestMapping and @PathVariables of the following form:

    Code:
    @Controller
    @RequestMapping("/spring")
    class SpringController {
    
        @RequestMapping(value = "test/{var1}/{var2}/done", method = RequestMethod.GET)
        ResponseEntity<String> whoa(@PathVariable String var1, @PathVariable String var2)
        {
            println "Called "+var1+" "+var2
            HttpHeaders headers = new HttpHeaders();
            headers.contentType = MediaType.TEXT_PLAIN;
            return new ResponseEntity<String>("Wootlez^max", headers, HttpStatus.OK)
        }
    }
    Request:
    Code:
    /spring/test/x/y/done
    Output:
    Code:
    Called (*) (*)
    It would also seem that the only way to get Grails to dispatch to Spring's url handler is to map my RESTful url to RESTful url.dispatch.

    So -- URLMappings.groovy:
    Code:
    "/spring/test/$var1/$var2/done"(uri:"""/spring/test/$var1/$var2/done.dispatch""")
    Anyone know how to get these path variables bound to 'x' and 'y'?
    Bonus. Anyone know how to avoid having to specify URLMappings.groovy lines in addition to my Spring MVC annotations?
    Last edited by jhazen; May 9th, 2011 at 01:37 PM. Reason: cleanup oops

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •