Skip to content
Closed
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
@@ -1,6 +1,6 @@
package hello;

public class Greeting {
public class GreetingClass {

private long id;
private String content;
Expand Down
7 changes: 3 additions & 4 deletions complete/src/main/java/hello/GreetingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ public class GreetingController {

@GetMapping("/greeting")
public String greetingForm(Model model) {
model.addAttribute("greeting", new Greeting());
return "greeting";
model.addAttribute("greeting_attribute", new GreetingClass());
return "greeting_template";
}

@PostMapping("/greeting")
public String greetingSubmit(@ModelAttribute Greeting greeting) {
public String greetingSubmit(@ModelAttribute GreetingClass result) {
return "result";
}

}
15 changes: 0 additions & 15 deletions complete/src/main/resources/templates/greeting.html

This file was deleted.

15 changes: 15 additions & 0 deletions complete/src/main/resources/templates/greeting_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Handling Form Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Form</h1>
<form action="#" th:action="@{/greeting}" th:object="${greeting_attribute}" method="post">
<p>Id: <input type="number" th:field="*{id}"/></p>
<p>Message: <input type="text" th:field="*{content}"/></p>
<p><input type="submit" value="Submit"/> <input type="reset" value="Reset"/></p>
</form>
</body>
</html>
12 changes: 6 additions & 6 deletions complete/src/main/resources/templates/result.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<head>
<title>Getting Started: Handling Form Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Result</h1>
<p th:text="'id: ' + ${greeting.id}" />
<p th:text="'content: ' + ${greeting.content}" />
<a href="/greeting">Submit another message</a>
<h1>Result</h1>
<p th:text="'id: ' + ${greetingClass.id}"/>
<p th:text="'content: ' + ${greetingClass.content}"/>
<a href="/greeting">Submit another message</a>
</body>
</html>