Java back-end server programming; includes various exercises
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
871 B

  1. package com.example.sqltest.web;
  2. import java.util.List;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.ui.Model;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RequestMethod;
  8. import com.example.sqltest.model.Customer;
  9. import com.example.sqltest.model.CustomerDAO;
  10. @Controller
  11. public class CustomerController {
  12. @Autowired
  13. private CustomerDAO customerDAO;
  14. @RequestMapping(
  15. value = "/customers",
  16. method = RequestMethod.GET
  17. )
  18. public String customerWebFormGet(Model dataModel) {
  19. List<Customer> customers = customerDAO.findAll();
  20. dataModel.addAttribute("customers", customers);
  21. return "customers";
  22. }
  23. @RequestMapping("*")
  24. public String redirectWebForm() {
  25. return "redirect:/customers";
  26. }
  27. }