Skip to content

Commit 24bba5a

Browse files
June LeeJune Lee
authored andcommitted
Modles Binding
1 parent d770d13 commit 24bba5a

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
import org.launchcode.codingeventsv3.models.Event;
55
import org.springframework.stereotype.Controller;
66
import org.springframework.ui.Model;
7-
import org.springframework.web.bind.annotation.GetMapping;
8-
import org.springframework.web.bind.annotation.PostMapping;
9-
import org.springframework.web.bind.annotation.RequestMapping;
10-
import org.springframework.web.bind.annotation.RequestParam;
7+
import org.springframework.web.bind.annotation.*;
118

129
import java.util.ArrayList;
1310
import java.util.List;
@@ -30,8 +27,8 @@ public String renderEventForm() {
3027

3128

3229
@PostMapping("create")
33-
public String createEventHandler(@RequestParam String eventName, @RequestParam String eventDescription) {
34-
EventData.add(new Event(eventName, eventDescription));
30+
public String createEventHandler(@ModelAttribute Event newEvent) {
31+
EventData.add(newEvent);
3532
return "redirect:/events";
3633
}
3734

codingeventsv3/src/main/resources/templates/events/create.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ <h1>Create Event</h1>
1010
<div class="form-group">
1111
<label>Name</label>
1212

13-
<input type="text" name="eventName" class="form-control">
13+
<input type="text" name="name" class="form-control">
1414

1515
</div>
1616

1717
<div class="form-group">
1818

1919
<label>Description</label>
2020

21-
<input type="text" name="eventDescription" class="form-control">
21+
<input type="text" name="description" class="form-control">
2222
</div>
2323

2424
<div class="form-group">

0 commit comments

Comments
 (0)