Results 1 to 1 of 1

Thread: @RequestMapping, URITemplate and optional path parameters

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Default @RequestMapping, URITemplate and optional path parameters

    I have the following mapping:

    Code:
    @RequestMapping(value = "/{first}/**/{last}", method = RequestMethod.GET)
    public String test(@PathVariable("first") String first,  @PathVariable("last")  String last) {}
    Which for the following URIs:
    foo/a/b/c/d/e/f/g/h/bar
    foo/a/bar
    foo/bar

    maps foo to first and bar to last and works fine.

    What I would like is something that maps everything between foo and bar into a single path param, or null if there is no middle (as in the last URI example):

    Code:
    @RequestMapping(value = "/{first}/{middle:[some regex here?]}/{last}", method = RequestMethod.GET)
    public String test(@PathVariable("first") String first,  @PathVariable("middle") String middle, @PathVariable("last")  String last) {}
    Pretty stuck on the regex since I was hoping that something simple like {middle:.*}, which only maps to /foo/a/bar, or {middle: (.*/)*}, which seems to map to nothing.

    Does the AntPathStringMatcher tokenize upon "/" prior to applying regex patterns? (making patterns that cross a / impossible) or is there a solution?

    FYI on Spring 3.1M2
    Last edited by laochan; Oct 20th, 2011 at 02:58 PM.

Tags for this Thread

Posting Permissions

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