O'Reilly logo

Spring MVC Beginner’s Guide by Amuthan G

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using URI template patterns

In the previous chapters, we saw how to map a particular URL to a controller method; for example, if the URL entered was http://localhost:8080/webstore/products, we mapped that request to the list method of ProductController and listed all the product information on the web page.

What if we want to list only a subset of the products based on category, for instance, we want to display only the products that fall under the category of laptops if the user entered the URL http://localhost:8080/webstore/products/laptop? Similarly, what if the URL is http://localhost:8080/webstore/products/tablet and we would like to show only tablets on the web page?

One way to do this is to have a separate request mapping method in the controller ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required