-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cc6009
commit 85dbe54
Showing
4 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/hello/typeconverter/controller/FormatterController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package hello.typeconverter.controller; | ||
|
||
import lombok.Data; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.format.annotation.NumberFormat; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Controller | ||
public class FormatterController { | ||
|
||
@GetMapping("/formatter/edit") | ||
public String formatterForm(Model model) { | ||
|
||
Form form = new Form(); | ||
form.setNumber(10000); | ||
form.setLocalDateTime(LocalDateTime.now()); | ||
|
||
model.addAttribute("form", form); | ||
return "formatter-form"; | ||
} | ||
|
||
@PostMapping("/formatter/edit") | ||
public String formatterEdit(@ModelAttribute Form form) { | ||
return "formatter-view"; | ||
} | ||
|
||
@Data | ||
static class Form { | ||
@NumberFormat(pattern = "###,###") | ||
private Integer number; | ||
|
||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
private LocalDateTime localDateTime; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
|
||
<form th:object="${form}" th:method="post"> | ||
number <input type="text" th:field="*{number}"><br/> | ||
localDateTime <input type="text" th:field="*{localDateTime}"><br/> | ||
<input type="submit"/> | ||
</form> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
|
||
<ul> | ||
<li>${form.number}: <span th:text="${form.number}" ></span></li> | ||
<li>${{form.number}}: <span th:text="${{form.number}}" ></span></li> | ||
<li>${form.localDateTime}: <span th:text="${form.localDateTime}" ></span></li> | ||
<li>${{form.localDateTime}}: <span th:text="${{form.localDateTime}}" ></span></li> | ||
</ul> | ||
|
||
</body> | ||
</html> |