Skip to content

Chapter 11 Exercise upload #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: add-bootstrap
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
Expand All @@ -17,11 +18,15 @@
@RequestMapping("events")
public class EventController {

private static List<String> events = new ArrayList<>();
private static HashMap<String, String> events = new HashMap<>();

@GetMapping
public String displayAllEvents(Model model) {
model.addAttribute("title", "All Events");
// model.addAttribute("events", events);
events.put("WWDC", "Apple Developer Conference");
events.put("LaunchCode", "LiftOff");
events.put("WWT", "Apprenticeship");
model.addAttribute("events", events);
return "events/index";
}
Expand All @@ -32,10 +37,10 @@ public String displayCreateEventForm(Model model) {
return "events/create";
}

@PostMapping("create")
public String processCreateEventForm(@RequestParam String eventName) {
events.add(eventName);
return "redirect:";
}
// @PostMapping("create")
// public String processCreateEventForm(@RequestParam String eventName) {
// events.put(eventName);
// return "redirect:";
// }

}
21 changes: 17 additions & 4 deletions src/main/resources/templates/events/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@
<body>

<header th:replace="fragments :: header"></header>

<ul>
<table class="table table-striped">
<tr>
<th>Event Name</th>
<th>Description</th>
<th>Address</th>
</tr>
<th:block th:each="event : ${events}">
<li th:text="${event}"></li>
<tr>
<td th:text="${event.getKey()}"></td>
<td th:text="${event.getValue()}"></td>
<td th:replace ="fragments :: address"></td>
</tr>
</th:block>
</ul>
</table>
<!--<ul>-->
<!-- <th:block th:each="event : ${events}">-->
<!-- <li th:text="${event}"></li>-->
<!-- </th:block>-->
<!--</ul>-->

</body>
</html>
2 changes: 2 additions & 0 deletions src/main/resources/templates/fragments.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ <h1 th:text="${title}">Coding Events</h1>
</ul>
</nav>

<td th:fragment="address">54321 Descending address BLVD</td>

</body>
</html>