Results 1 to 2 of 2

Thread: Exactly URI pattern matching

  1. #1
    Join Date
    Nov 2007
    Posts
    4

    Default 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. #2

    Default

    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 {
    		..
    	}
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •