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} + +