Announcement Announcement Module
Collapse
No announcement yet.
ReST Controller Conflicting URI Patterns Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ReST Controller Conflicting URI Patterns

    With Spring 3 (3.0.5-RELEASE), is it possible to set up a ReSTful Controller (using the @Controller annotation) to respond to different, but conflicting, URI patterns with a precedence rule?

    For example, can I have two methods as follows?

    @RequestMapping(value = "/profile/{profileId}", method = RequestMethod.GET)
    public ModelAndView getProfile(final @RequestParam(value = "profileId") String pProfileId) {
    ...
    }

    and

    @RequestMapping(value = "/profile/current", method = RequestMethod.GET)
    public ModelAndView getCurrentProfile() {
    ...
    }

    and if so, how do I ensure that the constant form (e.g. "/profile/current") of the URI takes precedence over the parameterized form (e.g. "/profile/{profileId}") - i.e. it does not think that "current" is a profile ID.

  • #2
    Have you tried it? Does it not work?

    Comment


    • #3
      My Mistake

      I tried it, as discussed, and it did not work - I would get an error indicating that my request was not valid.

      After much troubleshooting, I realised that I used @RequestParam where I should have used @PathVariable.

      i.e.

      Code:
          @RequestMapping(value = "/profile/{profileId}", method = RequestMethod.GET)
          public ModelAndView getProfile(final @PathVariable(value = "profileId") String pProfileId) {
              ...
          }
      It is all sorted now

      Comment

      Working...
      X