Announcement Announcement Module
Collapse
No announcement yet.
Exactly URI pattern matching Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exactly URI pattern matching

    Hi,
    Iím using Spring 3.0 to rewrite existing application. However, Iím having some problems with appropriate handler mappings.
    I have defined the following controllers:
    Code:
    @Controller
    public class CarsController {
    	@RequestMapping("/cars")
    	public void handleRequest(Model model, HttpServletRequest r) throws Exception {
    		..
    	}
    }
    @Controller
    public class CarDetailsController {
    	@RequestMapping("/cars/{id}_{model}")
    	public void handleRequest(Model model, HttpServletRequest r) throws Exception {
    		..
    	}
    }
    applicationContext-mvc.xml (used by web.xml, DispatcherServlet):
    Code:
    	<context:component-scan base-package="org.xxx.*" />
    	<mvc:annotation-driven />
    The problem is that I want CarsController to handle ONLY this url "/cars", without those mappings : [/cars.*] , [/cars/]
    The other mappings matching ONLY this pattern /cars/{id}_{model} should be handled by CarDetailsController.

    I would really appreciate any help that can help me to configure controllers to handle only given pattern.

    Regards,
    Michal

  • #2
    You need to annotate the CarsController at the class level.

    See here for more details: http://static.springsource.org/sprin...pping-advanced

    Code:
    @Controller
    @RequestMapping("/cars")
    public class CarsController {
    	@RequestMapping("/")
    	public void handleRequest(Model model, HttpServletRequest r) throws Exception {
    		..
    	}
    }
    And then annotate CarDetailsController agian at the class level

    Code:
    @Controller
    @RequestMapping("/cars/{id}_{model}")
    public class CarDetailsController {
    	@RequestMapping("/")
    	public void handleRequest(Model model, HttpServletRequest r, @PathVariable String id, @PathVariable String model) throws Exception {
    		..
    	}
    }

    Comment

    Working...
    X