diff --git a/typeconverter/src/main/java/hello/typeconverter/controller/FormatterController.java b/typeconverter/src/main/java/hello/typeconverter/controller/FormatterController.java new file mode 100644 index 00000000..82235e9b --- /dev/null +++ b/typeconverter/src/main/java/hello/typeconverter/controller/FormatterController.java @@ -0,0 +1,41 @@ +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; + } +} diff --git a/typeconverter/src/main/resources/templates/formatter-form.html b/typeconverter/src/main/resources/templates/formatter-form.html new file mode 100644 index 00000000..b164e804 --- /dev/null +++ b/typeconverter/src/main/resources/templates/formatter-form.html @@ -0,0 +1,14 @@ + + +
+ +