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 }
2827
28+ //lives at /events/create
29+ @ GetMapping ("create" )
30+ public String renderCreateEventForm () {
31+ return "events/create" ;
32+ }
33+ //lives at /events/create
34+ @ PostMapping ("create" )
35+ public String createEvent (@ RequestParam String eventName ) {
36+ events .add (eventName );
37+ return "redirect:" ;
38+ }
39+
2940}
Original file line number Diff line number Diff line change 1+ body {
2+ font-size : 18px ;
3+ color : purple;
4+ }
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en " xmlns:th ="http://www.thymeleaf.org/ ">
3+ < head th:replace ="fragments :: head "> </ head >
4+ < body class ="container ">
5+
6+ < h1 > Create Event</ h1 >
7+
8+ < nav th:replace ="fragments :: navigation "> </ nav >
9+
10+ < form method = "post " action ="/events/create " >
11+ < div class ="form-group ">
12+ < label > Name
13+ < input type ="text " name ="eventName " class ="form-control ">
14+ </ label >
15+ </ div >
16+ < div class ="form-group ">
17+ < input type ="submit " value ="Create Event " class ="btn btn-success ">
18+ </ div >
19+ </ form >
20+
21+ </ body >
22+ </ html >
Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22< html lang ="en " xmlns:th ="http://www.thymeleaf.org/ ">
3- < head >
4- < meta charset ="UTF-8 "/>
5- < title > Coding Events</ title >
6- </ head >
7- < body >
3+ < head th:replace ="fragments :: head "> </ head >
4+ < body class ="container ">
85
96< h1 > All Events</ h1 >
107
11- < ul >
12- < th:block th:each ="event : ${events} ">
13- < li th:text ="${event} "> </ li >
14- </ th:block >
15- </ ul >
8+
9+ < nav th:replace ="fragments :: navigation "> </ nav >
10+
11+ < p th:unless ="${events} and ${events.size()} "> No events!</ p >
12+
13+ < table class ="table table-striped ">
14+ < thead >
15+ < tr >
16+ < th > Name</ th >
17+ </ tr >
18+ </ thead >
19+ < tr th:each ="event : ${events} ">
20+ < td th:text = "${event} "> </ td >
21+ </ tr >
22+
23+ </ table >
1624
1725</ body >
18- </ html >
26+ </ html >
27+
28+ <
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en " xmlns:th ="http://www.thymeleaf.org/ ">
3+ < head th:fragment ="head ">
4+ < meta charset ="UTF-8 "/>
5+ < title > Coding Events</ title >
6+ < link rel ="
stylesheet "
href ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/css/bootstrap.min.css "
> 7+ < script src ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/js/bootstrap.min.js "
> </ script > 8+
9+ </ head >
10+ < body >
11+
12+ < nav th:fragment ="navigation ">
13+ < ul class ="nav ">
14+ < li class ="nav-item "> < a class ="nav-link " href ="/events "> All Events</ a > </ li >
15+ < li class ="nav-item "> < a class ="nav-link " href ="/events/create "> Create Event</ a > </ li >
16+ </ ul >
17+ </ nav >
18+
19+ </ body >
20+ </ html >
Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22< html lang ="en " xmlns:th ="http://www.thymeleaf.org/ ">
3- < head >
4- < meta charset ="UTF-8 "/>
5- < title > Coding Events</ title >
6- </ head >
7- < body >
3+
4+ < head th:replace ="fragments :: head "> </ head >
5+ < body class ="container ">
86
97< h1 > Coding Events</ h1 >
108
11- < nav >
12- < ul >
13- < li > < a href ="/events "> All Events</ a > </ li >
14- </ ul >
15- </ nav >
9+ < nav th:replace ="fragments :: navigation "> </ nav >
1610
1711</ body >
1812</ html >
You can’t perform that action at this time.
0 commit comments