Get the variable in the path of a URI
controller, java, spring-mvc
Solution
In Spring 3 you can use the @ PathVariable annotation to grab parts of the URL.
Here's a quick example from http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/
@RequestMapping(value="/hotels/{hotel}/bookings/{booking}", method=RequestMethod.GET)
public String getBooking(@PathVariable("hotel") long hotelId, @PathVariable("booking") long bookingId, Model model) {
Hotel hotel = hotelService.getHotel(hotelId);
Booking booking = hotel.getBooking(bookingId);
model.addAttribute("booking", booking);
return "booking";
}
Problem
In Spring MVC I have a controller that listens to all requests coming to `/my/app/path/controller/*`. Let's say a request comes to `/my/app/path/controller/blah/blah/blah/1/2/3`. How do I get the `/blah/blah/blah/1/2/3` part, i.e. the part that matches the `*` in the handler mapping definition. In other words, I am looking for something similar that `pathInfo` does for servlets but for controllers.