, :
say: NoProductsFoundException, .
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value=HttpStatus.NOT_FOUND, reason="No products found under this category")
public class NoProductsFoundException extends RuntimeException{
private static final long serialVersionUID =3935230281455340039L;
}
:
@RequestMapping("/{category}")
public String getProductsByCategory(Model
model,@PathVariable("category") String category) {
List<Product> products = productService.getProductsByCategory(category);
if (products == null || products.isEmpty()) {
throw new NoProductsFoundException ();
}
model.addAttribute("products", products);
return "products";
}
