File tree Expand file tree Collapse file tree
java/org/launchcode/codingevents/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import org .springframework .stereotype .Controller ;
44import org .springframework .web .bind .annotation .GetMapping ;
5+ import org .springframework .web .bind .annotation .PostMapping ;
56import org .springframework .web .bind .annotation .RequestMapping ;
67import org .springframework .ui .Model ;
8+ import org .springframework .web .bind .annotation .RequestParam ;
79
810import java .util .ArrayList ;
911import java .util .List ;
1517@ RequestMapping ("events" )
1618public class EventController {
1719
20+ private static List <String > events = new ArrayList <>();
21+
1822 @ GetMapping
1923 public String displayAllEvents (Model model ) {
20- List <String > events = new ArrayList <>();
21- events .add ("Code With Pride" );
22- events .add ("Strange Loop" );
23- events .add ("Apple WWDC" );
24- events .add ("SpringOne Platform" );
2524 model .addAttribute ("events" , events );
2625 return "events/index" ;
2726 }
@@ -31,4 +30,10 @@ public String renderCreateEventForm(){
3130 return "events/create" ;
3231 }
3332
33+ @ PostMapping ("create" )
34+ public String createEvent (@ RequestParam String eventName ){
35+ events .add (eventName );
36+ return "redirect:/events" ;
37+ }
38+
3439}
Original file line number Diff line number Diff line change 88
99< h1 > All Events</ h1 >
1010
11+ < p th:unless = "${events} and ${events.size()} "> No Events!</ p >
12+
1113< ul >
1214 < th:block th:each ="event : ${events} ">
1315 < li th:text ="${event} "> </ li >
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en " xmlns:th ="https://www.thymeleaf.org/ ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Title</ title >
6+ </ head >
7+ < body >
8+
9+ </ body >
10+ </ html >
You can’t perform that action at this time.
0 commit comments