Skip to content

Commit 906ab1f

Browse files
committed
PART06: 재확인 - 자동생성된 VO 수정한 부분 DTO 분리
자동생성된 BoardVO를 수정한 부분이 있어서, 해당 부분을 BoardDTO로 분리하고 BoardVO는 BoardDTO가 소유(has a)하도록 했다.
1 parent 73c5b57 commit 906ab1f

9 files changed

Lines changed: 175 additions & 164 deletions

File tree

part06/jex05-board/src/main/java/org/fp024/controller/BoardController.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import lombok.AllArgsConstructor;
1212
import lombok.extern.slf4j.Slf4j;
1313
import org.fp024.domain.BoardAttachVO;
14+
import org.fp024.domain.BoardDTO;
1415
import org.fp024.domain.BoardVO;
1516
import org.fp024.domain.Criteria;
1617
import org.fp024.domain.PageDTO;
@@ -64,16 +65,16 @@ public String list(Criteria criteria, Model model) {
6465
public void register() {}
6566

6667
@PostMapping("/register")
67-
public String register(BoardVO board, RedirectAttributes rttr) {
68+
public String register(BoardDTO boardDTO, RedirectAttributes rttr) {
6869
LOGGER.info("====================================");
69-
LOGGER.info("register: {}", board);
70+
LOGGER.info("register: {}", boardDTO);
7071

71-
if (board.getAttachList() != null) {
72-
board.getAttachList().forEach(attach -> LOGGER.info(attach.toString()));
72+
if (boardDTO.getAttachList() != null) {
73+
boardDTO.getAttachList().forEach(attach -> LOGGER.info(attach.toString()));
7374
}
7475
LOGGER.info("====================================");
75-
service.register(board);
76-
rttr.addFlashAttribute("result", board.getBno());
76+
service.register(boardDTO);
77+
rttr.addFlashAttribute("result", boardDTO.getBoardVO().getBno());
7778
// Spring MVC가 내부적으로 response.sendRedirect()처리를 함
7879
return "redirect:/board/list";
7980
}
@@ -87,10 +88,10 @@ public void get(
8788

8889
@PostMapping("/modify")
8990
public String modify(
90-
BoardVO board, @ModelAttribute("criteria") Criteria criteria, RedirectAttributes rttr) {
91-
LOGGER.info("modify: {}", board);
91+
BoardDTO boardDTO, @ModelAttribute("criteria") Criteria criteria, RedirectAttributes rttr) {
92+
LOGGER.info("modify: {}", boardDTO);
9293

93-
if (service.modify(board)) {
94+
if (service.modify(boardDTO)) {
9495
rttr.addFlashAttribute("result", "success");
9596
}
9697
return "redirect:/board/list" + criteria.getLink();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.fp024.domain;
2+
3+
import java.util.List;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import lombok.ToString;
7+
8+
@Getter
9+
@Setter
10+
@ToString
11+
public class BoardDTO {
12+
private BoardVO boardVO;
13+
14+
/** 첨부파일 목록 */
15+
private List<BoardAttachVO> attachList;
16+
}
Lines changed: 109 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,115 @@
11
package org.fp024.domain;
22

33
import java.time.LocalDateTime;
4-
import java.util.List;
54
import javax.annotation.Generated;
65

76
public class BoardVO {
8-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
9-
private Long bno;
10-
11-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
12-
private String title;
13-
14-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
15-
private String content;
16-
17-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
18-
private String writer;
19-
20-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
21-
private LocalDateTime regdate;
22-
23-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
24-
private LocalDateTime updateDate;
25-
26-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
27-
private int replyCount;
28-
29-
/**
30-
* 첨부파일 목록
31-
*
32-
* <p>1:N 관계를 Mybatis Generator 로 만들어낼 수 없어서, 수동으로 기입한 필드
33-
*/
34-
private List<BoardAttachVO> attachList;
35-
36-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
37-
public Long getBno() {
38-
return bno;
39-
}
40-
41-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
42-
public void setBno(Long bno) {
43-
this.bno = bno;
44-
}
45-
46-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
47-
public String getTitle() {
48-
return title;
49-
}
50-
51-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
52-
public void setTitle(String title) {
53-
this.title = title == null ? null : title.trim();
54-
}
55-
56-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
57-
public String getContent() {
58-
return content;
59-
}
60-
61-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
62-
public void setContent(String content) {
63-
this.content = content == null ? null : content.trim();
64-
}
65-
66-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
67-
public String getWriter() {
68-
return writer;
69-
}
70-
71-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
72-
public void setWriter(String writer) {
73-
this.writer = writer == null ? null : writer.trim();
74-
}
75-
76-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
77-
public LocalDateTime getRegdate() {
78-
return regdate;
79-
}
80-
81-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
82-
public void setRegdate(LocalDateTime regdate) {
83-
this.regdate = regdate;
84-
}
85-
86-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
87-
public LocalDateTime getUpdateDate() {
88-
return updateDate;
89-
}
90-
91-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
92-
public void setUpdateDate(LocalDateTime updateDate) {
93-
this.updateDate = updateDate;
94-
}
95-
96-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
97-
public int getReplyCount() {
98-
return replyCount;
99-
}
100-
101-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
102-
public void setReplyCount(int replyCount) {
103-
this.replyCount = replyCount;
104-
}
105-
106-
public void setAttachList(List<BoardAttachVO> attachList) {
107-
this.attachList = attachList;
108-
}
109-
110-
public List<BoardAttachVO> getAttachList() {
111-
return attachList;
112-
}
113-
114-
@Override
115-
@Generated("org.mybatis.generator.api.MyBatisGenerator")
116-
public String toString() {
117-
StringBuilder sb = new StringBuilder();
118-
sb.append(getClass().getSimpleName());
119-
sb.append(" [");
120-
sb.append("Hash = ").append(hashCode());
121-
sb.append(", bno=").append(bno);
122-
sb.append(", title=").append(title);
123-
sb.append(", content=").append(content);
124-
sb.append(", writer=").append(writer);
125-
sb.append(", regdate=").append(regdate);
126-
sb.append(", updateDate=").append(updateDate);
127-
sb.append(", replyCount=").append(replyCount);
128-
sb.append(", attachList=").append(attachList);
129-
sb.append("]");
130-
return sb.toString();
131-
}
132-
}
7+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
8+
private Long bno;
9+
10+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
11+
private String title;
12+
13+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
14+
private String content;
15+
16+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
17+
private String writer;
18+
19+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
20+
private LocalDateTime regdate;
21+
22+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
23+
private LocalDateTime updateDate;
24+
25+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
26+
private int replyCount;
27+
28+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
29+
public Long getBno() {
30+
return bno;
31+
}
32+
33+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
34+
public void setBno(Long bno) {
35+
this.bno = bno;
36+
}
37+
38+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
39+
public String getTitle() {
40+
return title;
41+
}
42+
43+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
44+
public void setTitle(String title) {
45+
this.title = title == null ? null : title.trim();
46+
}
47+
48+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
49+
public String getContent() {
50+
return content;
51+
}
52+
53+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
54+
public void setContent(String content) {
55+
this.content = content == null ? null : content.trim();
56+
}
57+
58+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
59+
public String getWriter() {
60+
return writer;
61+
}
62+
63+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
64+
public void setWriter(String writer) {
65+
this.writer = writer == null ? null : writer.trim();
66+
}
67+
68+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
69+
public LocalDateTime getRegdate() {
70+
return regdate;
71+
}
72+
73+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
74+
public void setRegdate(LocalDateTime regdate) {
75+
this.regdate = regdate;
76+
}
77+
78+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
79+
public LocalDateTime getUpdateDate() {
80+
return updateDate;
81+
}
82+
83+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
84+
public void setUpdateDate(LocalDateTime updateDate) {
85+
this.updateDate = updateDate;
86+
}
87+
88+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
89+
public int getReplyCount() {
90+
return replyCount;
91+
}
92+
93+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
94+
public void setReplyCount(int replyCount) {
95+
this.replyCount = replyCount;
96+
}
97+
98+
@Override
99+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
100+
public String toString() {
101+
StringBuilder sb = new StringBuilder();
102+
sb.append(getClass().getSimpleName());
103+
sb.append(" [");
104+
sb.append("Hash = ").append(hashCode());
105+
sb.append(", bno=").append(bno);
106+
sb.append(", title=").append(title);
107+
sb.append(", content=").append(content);
108+
sb.append(", writer=").append(writer);
109+
sb.append(", regdate=").append(regdate);
110+
sb.append(", updateDate=").append(updateDate);
111+
sb.append(", replyCount=").append(replyCount);
112+
sb.append("]");
113+
return sb.toString();
114+
}
115+
}

part06/jex05-board/src/main/java/org/fp024/service/BoardService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
import java.util.List;
44
import org.fp024.domain.BoardAttachVO;
5+
import org.fp024.domain.BoardDTO;
56
import org.fp024.domain.BoardVO;
67
import org.fp024.domain.Criteria;
78

89
public interface BoardService {
9-
void register(BoardVO board);
10+
void register(BoardDTO boardDTO);
1011

1112
BoardVO get(Long bno);
1213

13-
boolean modify(BoardVO board);
14+
boolean modify(BoardDTO boardDTO);
1415

1516
boolean remove(Long bno);
1617

part06/jex05-board/src/main/java/org/fp024/service/BoardServiceImpl.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import lombok.RequiredArgsConstructor;
2020
import lombok.extern.slf4j.Slf4j;
2121
import org.fp024.domain.BoardAttachVO;
22+
import org.fp024.domain.BoardDTO;
2223
import org.fp024.domain.BoardVO;
2324
import org.fp024.domain.Criteria;
2425
import org.fp024.mapper.BoardAttachMapper;
@@ -63,8 +64,8 @@ public class BoardServiceImpl implements BoardService {
6364
private final BoardAttachMapper attachMapper;
6465

6566
@Override
66-
public void register(BoardVO board) {
67-
LOGGER.info("register..... {}", board);
67+
public void register(BoardDTO boardDTO) {
68+
LOGGER.info("register..... {}", boardDTO);
6869
// insertSelectKey와 insert를 따로 분리해서 만들지 않았다, 항상 Key 프로퍼티를 설정해서 반환한다.
6970
// 바로 모델을 insert를 하면 board 모델의 등록/수정일시가 null일 경우 null로 업데이트를 할 수 있으므로 명시적으로 정해준다.
7071
// 테이블 생성시 SYSDATE 기본값이 동작하도록 명시적으로 지정해줄 필요가 있었다.
@@ -85,15 +86,16 @@ public void register(BoardVO board) {
8586
.render(RenderingStrategies.MYBATIS3));
8687
*/
8788
// 위의 코드보다 INSERT 직전 입력하지 않을 값을 명확하게하고 선택적 INSERT하는게 더 관리에 나을 수 있어보인다.
89+
BoardVO board = boardDTO.getBoardVO();
8890
board.setRegdate(null);
8991
board.setUpdateDate(null);
9092
mapper.insertSelective(board);
9193

92-
if (board.getAttachList() == null || board.getAttachList().isEmpty()) {
94+
if (boardDTO.getAttachList() == null || boardDTO.getAttachList().isEmpty()) {
9395
return;
9496
}
9597

96-
board
98+
boardDTO
9799
.getAttachList()
98100
.forEach(
99101
attach -> {
@@ -114,8 +116,10 @@ public BoardVO get(Long bno) {
114116

115117
@Transactional
116118
@Override
117-
public boolean modify(BoardVO board) {
118-
LOGGER.info("modify..... {}", board);
119+
public boolean modify(BoardDTO boardDTO) {
120+
LOGGER.info("modify..... {}", boardDTO);
121+
122+
BoardVO board = boardDTO.getBoardVO();
119123

120124
attachMapper.delete(
121125
c -> c.where(BoardAttachVODynamicSqlSupport.bno, isEqualTo(board.getBno())));
@@ -132,8 +136,8 @@ public boolean modify(BoardVO board) {
132136
.where(BoardVODynamicSqlSupport.bno, isEqualTo(board.getBno())))
133137
== 1;
134138

135-
if (modifyResult && board.getAttachList() != null && !board.getAttachList().isEmpty()) {
136-
board
139+
if (modifyResult && boardDTO.getAttachList() != null && !boardDTO.getAttachList().isEmpty()) {
140+
boardDTO
137141
.getAttachList()
138142
.forEach(
139143
attach -> {

0 commit comments

Comments
 (0)