Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.amuponda.estorehack.client.web.controller; import com.amuponda.estorehack.business.domain.Category; import com.amuponda.estorehack.business.service.CategoryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.RequestMapping; import static org.springframework.web.bind.annotation.RequestMethod.GET; import static org.springframework.web.bind.annotation.RequestMethod.POST; /** * * @author amuponda */ @Controller @RequestMapping("/productCategories") public class CategoryController { @Autowired private CategoryService categoryService; /** * render the form for product categories * @param model * @return */ @RequestMapping(value = "/add", method = GET) public String getProductCategoryForm(Model model) { model.addAttribute(new Category()); return "category/categoryForm"; } @RequestMapping(value = "/add", method = POST) public String processCategory(Category category) { categoryService.save(category); return "redirect:/"; } }