Skip to content

Commit f0d32f7

Browse files
committed
adding model class
1 parent f43b1d6 commit f0d32f7

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/main/java/org/launchcode/codingevents/controllers/EventController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.launchcode.codingevents.controllers;
22

3+
import org.launchcode.codingevents.models.Event;
34
import org.springframework.stereotype.Controller;
45
import org.springframework.web.bind.annotation.GetMapping;
56
import org.springframework.web.bind.annotation.PostMapping;
@@ -17,7 +18,7 @@
1718
@RequestMapping("events")
1819
public class EventController {
1920

20-
private static List<String> events = new ArrayList<>();
21+
private static List<Event> events = new ArrayList<>();
2122

2223
@GetMapping
2324
public String displayAllEvents(Model model) {
@@ -35,7 +36,7 @@ public String renderCreateEventForm(Model model) {
3536

3637
@PostMapping("create")
3738
public String createEvent(@RequestParam String eventName) {
38-
events.add(eventName);
39+
events.add(new Event(eventName));
3940
return "redirect:/events";
4041

4142
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.launchcode.codingevents.models;
2+
3+
public class Event {
4+
5+
private String name;
6+
7+
public Event(String name) {
8+
this.name = name;
9+
}
10+
11+
public String getName() {
12+
return name;
13+
}
14+
15+
public void setName(String name) {
16+
this.name = name;
17+
}
18+
19+
@Override
20+
public String toString() {
21+
return name;
22+
}
23+
}

src/main/resources/templates/events/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</tr>
1717
</thead>
1818
<tr th:each="event : ${events}">
19-
<td th:text="${event}"></td>
19+
<td th:text="${event.name}"></td>
2020
</tr>
2121
</table>
2222

0 commit comments

Comments
 (0)