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 ;
1012
11- /**
12- * Created by Chris Bay
13- */
13+
1414@ Controller
1515@ RequestMapping ("events" )
1616public class EventController {
1717
18+ private static List <String > events = new ArrayList <>();
19+
1820 @ GetMapping
1921 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" );
22+ model .addAttribute ("title" , "All Events" );
2523 model .addAttribute ("events" , events );
2624 return "events/index" ;
2725 }
2826
29- }
27+ @ GetMapping ("create" )
28+ public String displayCreateEventForm (Model model ) {
29+ model .addAttribute ("title" , "Create Event" );
30+ return "events/create" ;
31+ }
32+
33+ @ PostMapping ("create" )
34+ public String processCreateEventForm (@ RequestParam String eventName ) {
35+ events .add (eventName );
36+ return "redirect:/events" ;
37+ }
38+
39+ }
Original file line number Diff line number Diff line change 33import org .springframework .stereotype .Controller ;
44import org .springframework .web .bind .annotation .GetMapping ;
55
6- /**
7- * Created by Chris Bay
8- */
6+
97@ Controller
108public class HomeController {
119
Original file line number Diff line number Diff line change 1+ let appName = "Coding Events" ;
Original file line number Diff line number Diff line change 1+ body {
2+ font-size : 18px ;
3+ }
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+ < header th:replace ="fragments :: header "> </ header >
7+
8+ < form method ="post ">
9+ < div class ="form-group ">
10+ < label > Name
11+ < input type ="text " name ="eventName " class ="form-control ">
12+ </ label >
13+ </ div >
14+ < br >
15+ < div class ="form-group ">
16+ < input type ="submit " value ="Create " class ="btn btn-success ">
17+ </ div >
18+ </ form >
19+
20+ </ body >
21+ </ 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
9- < h1 > All Events </ h1 >
6+ < header th:replace =" fragments :: header " > </ header >
107
11- < ul >
12- < th:block th:each ="event : ${events} ">
13- < li th:text ="${event} "> </ li >
14- </ th:block >
15- </ ul >
8+ < table class ="table table-striped ">
9+ < thead >
10+ < tr >
11+ < th > Name</ th >
12+ </ tr >
13+ </ thead >
14+ < tr th:each ="event : ${events} ">
15+ < td th:text ="${event} "> </ td >
16+ </ tr >
17+ </ table >
1618
1719</ body >
1820</ html >
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+ </ head >
9+ < body >
10+
11+ < nav th:fragment ="header ">
12+ < h1 th:text ="${title} "> Coding Events</ h1 >
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+ < head th:replace ="fragments :: head "> </ head >
4+ < body class ="container ">
85
96< h1 > Coding Events</ h1 >
107
11- < nav >
12- < ul >
13- < li > < a href ="/events "> All Events</ a > </ li >
14- </ ul >
15- </ nav >
8+ < header th:replace ="fragments :: header "> </ header >
169
1710</ body >
1811</ html >
You can’t perform that action at this time.
0 commit comments