Time for action – adding the response status exception

First, we will look at the @ResponseStatus annotation (org.springframework.web.bind.annotation.ResponseStatus). In Chapter 3, Control Your Store with Controllers, we created a request mapping method to display products by category under the URI template, http://localhost:8080/webstore/products/{category}. If no products were found under the given category, we would show an empty web page, which is not correct semantically. We should show an HTTP status error to indicate that no products exist under the given category. Let's see how we can do that with the help of the @ResponseStatus annotation:

  1. Create a class called NoProductsFoundUnderCategoryException under the com.packt.webstore.exception ...

Get Spring MVC Beginner’s Guide 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.