Announcement Announcement Module
Collapse
No announcement yet.
@RequestMapping with params is not matching Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @RequestMapping with params is not matching

    I have several @RequestMapping that could potentially match several URLs but I specifically want one controller to map based on a similar URL + params. When stepping through the code for Spring 3.1 it seems that the RequestMappingInfoHandlerMapping pattern matches all @RequestMapping candidates but the comparator is not sorting the mappings with params first and is choosing the @RequestMapping without the params. I would think that the more specific and granular you are by specifying params, headers, or consumes/produces then it should match those first before a URL pattern match. Am I missing something, is this a bug, or does anyone know of anything I can do to override RequestMappingInfo#compareTo to check for patternsCondition + paramsCondition instead of patternsCondition otherwise paramsCondition?

    URL /test/1/edit?fieldName=Hello&fieldValue=World matches this controller method
    Code:
    @Controller
    @RequestMapping("/test/*")
    public class TestController {
    
        @RequestMapping("/{id}/edit")
        public ModelAndView edit(HttpServletRequest request,
                HttpServletResponse response,
                @PathVariable("id") int id) {
    
                return null; // ModelAndView not necessary for this example
        }
    }
    URL /test/1/edit?fieldName=Hello&fieldValue=World does NOT match this controller method
    Code:
    @Controller
    public class GenericController {
    
        @RequestMapping(value = "/{entityType}/{id}/edit", params = {"fieldName", "fieldValue"})
        public ModelAndView edit(HttpServletRequest request,
                HttpServletResponse response,
                @PathVariable("entityType") String entityType,
                @PathVariable("id") int id,
                @RequestParam(value = "fieldName", required = true) String fieldName,
                @RequestParam(value = "fieldValue", required = true) String fieldValue) {
    
                return null; // ModelAndView not necessary for this example
        }
    }
    Last edited by dukethrash; Apr 23rd, 2013, 01:07 PM.
Working...
X