|
3 | 3 | import org.springframework.stereotype.Controller; |
4 | 4 | import org.springframework.ui.Model; |
5 | 5 | import org.springframework.web.bind.annotation.GetMapping; |
| 6 | +import org.springframework.web.bind.annotation.PostMapping; |
6 | 7 | import org.springframework.web.bind.annotation.RequestMapping; |
| 8 | +import org.springframework.web.bind.annotation.RequestParam; |
7 | 9 |
|
8 | 10 | import java.util.ArrayList; |
| 11 | +import java.util.List; |
9 | 12 |
|
10 | 13 | @Controller |
11 | 14 | @RequestMapping("events") |
12 | 15 | public class EventController { |
13 | 16 |
|
| 17 | + private static List<String> events = new ArrayList<>(); |
14 | 18 | @GetMapping |
15 | | - public String events(Model model) { |
16 | | - ArrayList<String> eventNames = new ArrayList<>(); |
17 | | - eventNames.add("Stanley Cup"); |
18 | | - eventNames.add("World Cup"); |
19 | | - eventNames.add("Superbowl"); |
20 | | - eventNames.add("World Series"); |
21 | | - |
22 | | - model.addAttribute("events", eventNames); |
| 19 | + public String displayAllEvents(Model model) { |
| 20 | +// List<String> eventNames = new ArrayList<>(); |
| 21 | +// eventNames.add("Stanley Cup"); |
| 22 | +// eventNames.add("World Cup"); |
| 23 | +// eventNames.add("Superbowl"); |
| 24 | +// eventNames.add("World Series"); |
| 25 | +// |
| 26 | +// model.addAttribute("events", eventNames); |
| 27 | + model.addAttribute("events", events); |
23 | 28 | return "events/index"; |
24 | 29 | } |
| 30 | + |
| 31 | + // located @ /events/create |
| 32 | + @GetMapping("create") |
| 33 | + public String renderCreateEventForm() { |
| 34 | + return "events/create"; |
| 35 | + } |
| 36 | + |
| 37 | + //lives at /events/create |
| 38 | + @PostMapping("create") |
| 39 | + public String createEvent(@RequestParam String eventName) { |
| 40 | + events.add(eventName); |
| 41 | + return "redirect:/events"; |
| 42 | + |
| 43 | + } |
| 44 | + |
| 45 | + |
25 | 46 | } |
0 commit comments