Last active
September 25, 2018 07:06
-
-
Save mak9456/7b491404545e227911a2c3516d8e440a to your computer and use it in GitHub Desktop.
CustomerController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
@RequestMapping("/customer") | |
public class CustomerController { | |
@Autowired | |
private CustomerService customerService; | |
//@RequestMapping("/list") | |
@GetMapping("/list") | |
public String listcustomer(Model themodel) { | |
themodel.addAttribute("customers",customerService.getCustomer()); | |
return "list-customer"; | |
} | |
@GetMapping("/addcustomer") | |
public String addCustomer(Model themodel) { | |
System.out.println("in addCustomer "); | |
Customer customer=new Customer(); | |
themodel.addAttribute(customer); | |
return "show-customer-form"; | |
} | |
@PostMapping("/processform") | |
public String processForm(Model themodel,@ModelAttribute("customer") Customer newcustomer ) { | |
//adding logic here | |
customerService.addCustomer(newcustomer); | |
//display | |
themodel.addAttribute("customers",customerService.getCustomer()); | |
System.out.println("in process form"); | |
return "list-customer"; | |
} | |
@GetMapping("/update") | |
public String updateCustomer(Model themodel,@RequestParam("customerId") int theId ) { | |
themodel.addAttribute("customer",customerService.getSingleCustomer(theId)); | |
return "show-customer-form"; | |
} | |
@GetMapping("/delete") | |
public String deleteCustomer(Model themodel,@RequestParam("customerId") int theId ) { | |
//adding logic here | |
customerService.deleteCustomer(theId); | |
//display | |
themodel.addAttribute("customers",customerService.getCustomer()); | |
System.out.println("in process form"); | |
return "list-customer"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment