Skip to content

Commit

Permalink
게시물 추가될 때 추가된 날짜가 자동으로 입력
Browse files Browse the repository at this point in the history
  • Loading branch information
wjxor committed Jul 17, 2021
1 parent 26f560d commit 2a911ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.bind.annotation.ResponseBody;

import com.wjxor.untact.dto.Article;
import com.wjxor.untact.util.Util;

@Controller
public class UsrArticleController {
Expand Down Expand Up @@ -42,7 +43,10 @@ public List<Article> showList() {

@RequestMapping("/usr/article/doAdd")
@ResponseBody
public Map<String, Object> doAdd(String regDate, String title, String body) {
public Map<String, Object> doAdd(String title, String body) {

String regDate = Util.getNowDateStr();

articles.add(new Article(++articlesLastId, regDate, title, body));

Map<String, Object> rs = new HashMap<>();
Expand All @@ -53,6 +57,8 @@ public Map<String, Object> doAdd(String regDate, String title, String body) {
return rs;
}



@RequestMapping("/usr/article/doDelete")
@ResponseBody
public Map<String, Object> doDelete(int id) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/wjxor/untact/util/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.wjxor.untact.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Util {
public static String getNowDateStr() {
SimpleDateFormat format1 = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss");
Date time = new Date();

return format1.format(time);
}
}

0 comments on commit 2a911ed

Please sign in to comment.