Announcement Announcement Module
Collapse
No announcement yet.
Strange @RequestMapping and @PathVariable behavior Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange @RequestMapping and @PathVariable behavior

    Hi all!

    I'm working on a roo project and I came up with this "bug", or more likely, lack of knowledge on my side. I have the following custom controller (.java):

    Code:
    @RequestMapping("/visita/mobile/**")
    @Controller
    public class MyController {
    
    @RequestMapping(value = "/visita/mobile/test/{uno}/{dos}/{tres}", method = RequestMethod.GET)
        public String store2(
        		@PathVariable("uno") int uno, 
        		@PathVariable("dos") int dos, 
        		@PathVariable("tres") int tres,
        		ModelMap modelMap) {
    		System.out.println("It worked");
            modelMap.addAttribute("visitas", Visita.findAllVisitas());
            return "visita/list";
        }
    
    }
    Which is giving me this error when calling the resource http://localhost:8080/colombiamoda/v...ile/test/1/2/3:

    Failed to invoke handler method [public java.lang.String com.idlink.colombiamoda.web.MyController.store2(in t,int,int,org.springframework.ui.ModelMap)]; nested exception is java.lang.IllegalStateException: Could not find @PathVariable [uno] in @RequestMapping
    One thing I found is that if I remove one of the parameters like this:


    Code:
    @RequestMapping(value = "/visita/mobile/test/{uno}/{dos}/", method = RequestMethod.GET)
        public String store2(
        		@PathVariable("uno") int uno, 
        		@PathVariable("dos") int dos, 
        		ModelMap modelMap) {
    		System.out.println("It worked");
            modelMap.addAttribute("visitas", Visita.findAllVisitas());
            return "visita/list";
        }
    It works!. I really don't see what's happening. It seems like my controller handler cannot receive more than 2 parameters.

    Anyone has a clue!???

    THANKS A LOT!

  • #2
    Did anything come of this? Two years later I am dealing with the exact same problem.

    Any help or suggestions are appreciated.

    Comment

    Working...
    X