|
16 | 16 | @Controller |
17 | 17 | public class SpringController { |
18 | 18 |
|
19 | | - private static List<Car> carList = new ArrayList<Car>(); |
20 | | - |
21 | | - @RequestMapping(value = "/", method = RequestMethod.GET) |
22 | | - public String home(Locale locale, Model model) { |
23 | | - return "redirect:/cars"; |
24 | | - } |
25 | | - |
26 | | - static { |
27 | | - carList.add(new Car("Honda", "Civic")); |
28 | | - carList.add(new Car("Toyota", "Camry")); |
29 | | - carList.add(new Car("Nissan", "Altima")); |
30 | | - } |
31 | | - |
32 | | - |
33 | | - @RequestMapping(value = "/cars", method = RequestMethod.GET) |
34 | | - public String init(@ModelAttribute("model") ModelMap model) { |
35 | | - model.addAttribute("carList", carList); |
36 | | - return "index"; |
37 | | - } |
38 | | - |
39 | | - @RequestMapping(value = "/add", method = RequestMethod.POST) |
40 | | - public String addCar(@ModelAttribute("car") Car car) { |
41 | | - if (null != car && null != car.getMake() && null != car.getModel() |
42 | | - && !car.getMake().isEmpty() && !car.getModel().isEmpty()) { |
43 | | - carList.add(car); |
44 | | - } |
45 | | - return "redirect:/cars"; |
46 | | - } |
47 | | - |
| 19 | + private static List<Car> carList = new ArrayList<Car>(); |
| 20 | + |
| 21 | + @RequestMapping(value = "/", method = RequestMethod.GET) |
| 22 | + public String home(Locale locale, Model model) { |
| 23 | + return "redirect:/cars"; |
| 24 | + } |
| 25 | + |
| 26 | + static { |
| 27 | + carList.add(new Car("Honda", "Civic")); |
| 28 | + carList.add(new Car("Toyota", "Camry")); |
| 29 | + carList.add(new Car("Nissan", "Altima")); |
| 30 | + } |
| 31 | + |
| 32 | + @RequestMapping(value = "/cars", method = RequestMethod.GET) |
| 33 | + public String init(@ModelAttribute("model") ModelMap model) { |
| 34 | + model.addAttribute("carList", carList); |
| 35 | + return "index"; |
| 36 | + } |
| 37 | + |
| 38 | + @RequestMapping(value = "/add", method = RequestMethod.POST) |
| 39 | + public String addCar(@ModelAttribute("car") Car car) { |
| 40 | + if (null != car && null != car.getMake() && null != car.getModel() && !car.getMake().isEmpty() && !car.getModel().isEmpty()) { |
| 41 | + carList.add(car); |
| 42 | + } |
| 43 | + return "redirect:/cars"; |
| 44 | + } |
| 45 | + |
48 | 46 | } |
0 commit comments