Using parameters in @RequestMapping

We have seen how to use the @RequestMapping annotation to map the incoming request to a Controller method. So far, we have mapped static URL patterns in @RequestMapping. However, it is possible to map parameterized URLs (like those used in REST; see https://spring.io/understanding/REST) using @RequestMapping. The parameters are specified inside {}.

Let's add the feature to update an existing course. Here, we will only discuss how to code the Controller method for this feature. The complete code is available when you download the samples for this chapter.

Let's add the following method in CourseController:

 @RequestMapping("/course/update/{id}") public String updateCourse (@PathVariable int id, Model model) ...

Get Java EE 8 Development with Eclipse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.