Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7674591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:46:19+00:00 2026-05-31T16:46:19+00:00

I have a simple Controller that looks like this:- @Controller @RequestMapping(value = /groups) public

  • 0

I have a simple Controller that looks like this:-

@Controller
@RequestMapping(value = "/groups")
public class GroupsController {
    // mapping #1
    @RequestMapping(method = RequestMethod.GET)
    public String main(@ModelAttribute GroupForm groupForm, Model model) {
        ...
    }

    // mapping #2
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public String changeGroup(@PathVariable Long id, @ModelAttribute GroupForm groupForm, Model model) {
        ...
    }

    // mapping #3
    @RequestMapping(method = RequestMethod.POST)
    public String save(@Valid @ModelAttribute GroupForm groupForm, BindingResult bindingResult, Model model) {
        ...
    }
}

Basically, this page has the following functionalities:-

  • User visits main page (/groups GET).
  • User creates a new group (/groups POST) or selects a specific group (/groups/1 GET).
  • User edits an existing group (/groups/1 POST).

I understand how both GET request mappings work here. Mapping #2 is defined, otherwise (/groups/1 GET) will cause a “No mapping found” exception.

What I’m trying to understand here is why mapping #3 handles both (/groups POST) and (/groups/1 POST)? It makes sense that it should handle (/groups POST) here since the request mapping matches the URI. Why (/groups/1 POST) isn’t causing a “No mapping found” exception being thrown here? In fact, it almost seems like any POST with URI beginning with /groups (ex: /groups/bla/1 POST) will also be handled by mapping #3.

Can someone provide a clear explanation of this to me? Thanks much.

CLARIFICATION

I understand the fact that I can use more appropriate methods (like GET, POST, PUT or DELETE)… or I can create yet another request mapping to handle /groups/{id} POST.

However, what I want to really know is…

…. “Why does mapping #3 handle /groups/1 POST too?”

The “closest match” reasoning don’t seem to hold true because if I remove mapping #2, then I would think mapping #1 will handle /groups/1 GET, but it doesn’t and it causes a “No mapping found” exception.

I’m just a little stumped here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:46:20+00:00Added an answer on May 31, 2026 at 4:46 pm

    This is complicated, I think it is better to read the code.

    In Spring 3.0 The magic is done by method public Method resolveHandlerMethod(HttpServletRequest request) of the inner class ServletHandlerMethodResolver of org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.

    An instance of this class exists for every Request Controller Class, and has a field handlerMethods that contains a list of all the request methods.

    But let me summarize how I understand it

    • Spring first checks if at least one handler method matches (this can contain false negatives)
    • Then it creates a map of all really matching handler methods
    • Then it sorts the map by request path: RequestSpecificMappingInfoComparator
    • and takes the first one

    The sorting works this way: the RequestSpecificMappingInfoComparator first compares the path with the help of an AntPathMatcher, if two methods are equal according to this, then other metrics (like number of parameters, number of headers, etc.) are taken into account with respect to the request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple menu that looks like this: <ul class=menu> <li class=active><a href=<%=
I have a model that looks something like this: public class SampleModel { public
I have a simple question. I have a model that looks like this: public
I have a simple ViewController that looks like this: @interface MyViewController : UIViewController<UIScrollViewDelegate> {
I have a simple controller which returns images: public class ImageController : Controller {
I have a route that looks like the following: map.newsletter '/newsletter', :controller => newsletter
So, I have a page that looks like the following: alt text http://img704.imageshack.us/img704/5973/croppercapture3.png This
let say your controller action looks like this: public ActionResult Update(Car myCar) { }
I have a number of simple controller classes that use Doctrine's entity manager to
I have a simple controller called list_controller with an index that basically does def

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.