From 6ff28200b0498e8b8cfce17f9dd98f0814acf13d Mon Sep 17 00:00:00 2001 From: DK Lee Date: Sun, 14 Jun 2015 04:18:32 +0900 Subject: [PATCH] =?UTF-8?q?[=EB=B8=94=EB=A1=9C=EA=B7=B8=EA=B0=9C=EB=B0=9C?= =?UTF-8?q?=5F11]=20=EA=B8=80=20=EC=88=98=EC=A0=95,=20=EC=82=AD=EC=A0=9C..?= =?UTF-8?q?.=20(+Date=20=EB=B6=80=EB=B6=84=20=EB=B3=80=EA=B2=BD)=20http://?= =?UTF-8?q?millky.com/@origoni/post/1167?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 ++++-- .../millky/blog/domain/model/entity/Post.java | 9 +++++-- .../controller/PostController.java | 27 ++++++++++++++++--- src/main/webapp/WEB-INF/jsp/form.jsp | 9 ++++++- src/main/webapp/WEB-INF/jsp/post.jsp | 9 +++++++ 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 41d3ab3..3fc4c2e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.millky.blog spring-blog - 0.0.9-SNAPSHOT + 0.0.11-SNAPSHOT war SpringBlog @@ -33,9 +33,13 @@ com.h2database h2 - + + org.springframework.social + spring-social-facebook + + org.springframework.boot spring-boot-starter-web diff --git a/src/main/java/com/millky/blog/domain/model/entity/Post.java b/src/main/java/com/millky/blog/domain/model/entity/Post.java index b46d3cc..ea965fd 100644 --- a/src/main/java/com/millky/blog/domain/model/entity/Post.java +++ b/src/main/java/com/millky/blog/domain/model/entity/Post.java @@ -1,6 +1,6 @@ package com.millky.blog.domain.model.entity; -import java.util.Date; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; @@ -12,10 +12,14 @@ import lombok.Getter; import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.format.annotation.DateTimeFormat.ISO; + @Getter @Setter @Entity public class Post { + @Id @GeneratedValue int id; @@ -33,5 +37,6 @@ public class Post { @Column(length = 100000000) String content; - Date regDate; + @DateTimeFormat(iso = ISO.DATE_TIME) + LocalDateTime regDate; } diff --git a/src/main/java/com/millky/blog/presentation/controller/PostController.java b/src/main/java/com/millky/blog/presentation/controller/PostController.java index 7d8743d..fbaa175 100644 --- a/src/main/java/com/millky/blog/presentation/controller/PostController.java +++ b/src/main/java/com/millky/blog/presentation/controller/PostController.java @@ -1,6 +1,6 @@ package com.millky.blog.presentation.controller; -import java.util.Date; +import java.time.LocalDateTime; import java.util.List; import javax.validation.Valid; @@ -33,7 +33,7 @@ public String write(@Valid Post post, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return "form"; } - post.setRegDate(new Date()); + post.setRegDate(LocalDateTime.now()); return "redirect:/post/" + postDao.save(post).getId(); } @@ -50,4 +50,25 @@ public String view(Model model, @PathVariable int id) { model.addAttribute("post", post); return "post"; } -} \ No newline at end of file + + @RequestMapping("/{id}/delete") + public String delete(@PathVariable int id) { + postDao.delete(id); + return "redirect:/post/list"; + } + + @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET) + public String editor(Model model, @PathVariable int id) { + Post post = postDao.findOne(id); + model.addAttribute("post", post); + return "form"; + } + + @RequestMapping(value = "/{id}/edit", method = RequestMethod.POST) + public String edit(@Valid Post post, BindingResult bindingResult) { + if (bindingResult.hasErrors()) { + return "form"; + } + return "redirect:/post/" + postDao.save(post).getId(); + } +} diff --git a/src/main/webapp/WEB-INF/jsp/form.jsp b/src/main/webapp/WEB-INF/jsp/form.jsp index f015877..db2b640 100644 --- a/src/main/webapp/WEB-INF/jsp/form.jsp +++ b/src/main/webapp/WEB-INF/jsp/form.jsp @@ -74,7 +74,12 @@ - + + + + + + @@ -113,6 +118,8 @@ toolbar : document.getElementById('custom-toolbar'), editor : document.querySelector('[data-toggle="pen"]') }; + + $('#pen').html($('#content').val()); // create editor var pen = window.pen = new Pen(options); diff --git a/src/main/webapp/WEB-INF/jsp/post.jsp b/src/main/webapp/WEB-INF/jsp/post.jsp index 1a996b1..0438e56 100644 --- a/src/main/webapp/WEB-INF/jsp/post.jsp +++ b/src/main/webapp/WEB-INF/jsp/post.jsp @@ -70,6 +70,15 @@ ${post.content} + +