@RequestMapping(value = "search", method = RequestMethod.POST)
  public String search(@RequestParam Integer maxPrice, Model model) {
    List<Product> products = catalog.findByMaxPrice(maxPrice);
    model.addAttribute("products", products);

    return "searchResult";
  }
  @RequestMapping("edit")
  public String edit(Model model, @RequestParam Long id) {

    Product product = catalog.findById(id);
    model.addAttribute("product", product);

    return "editProduct";
  }
 @RequestMapping("save")
 public String save(@ModelAttribute Product product, BindingResult bindingResult, Model model) {
   if (bindingResult.hasErrors()) {
     model.addAttribute("product", product);
     return "editProduct";
   }
   catalog.addProduct(product);
   return "redirect:/product/list";
 }
  @RequestMapping("add")
  public String add(@ModelAttribute Product product, BindingResult bindingResult, Model model) {
    if (bindingResult.hasErrors()) {
      model.addAttribute("errorMessage", "price must be a number");
      return "newProduct";
    }

    catalog.addProduct(product);

    return "redirect:/product/list";
  }
  @RequestMapping("delete")
  public String delete(Model model, @RequestParam Long id) {

    catalog.deleteProduct(id);
    return "redirect:/product/list";
  }
  @RequestMapping("list")
  public String list(Model model) {

    model.addAttribute("products", catalog.getProducts());
    return "listProducts";
  }