Skip to content

Commit 05fb379

Browse files
committed
게시물 본문을 JSON으로 파싱해서 내려주는 속성 추가 boardContentJson)
웹에디터의 보기모드 등에서 사용하자!
1 parent ded316b commit 05fb379

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

part-last/my-board-mds/src/main/java/org/fp024/controller/BoardController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.fp024.domain.generated.BoardAttachVO;
1818
import org.fp024.domain.generated.BoardVO;
1919
import org.fp024.service.BoardService;
20+
import org.fp024.util.GsonHelper;
2021
import org.fp024.util.ProjectDataUtil;
2122
import org.springframework.http.HttpStatus;
2223
import org.springframework.http.MediaType;
@@ -86,7 +87,12 @@ public String register(BoardDTO boardDTO, RedirectAttributes rttr) {
8687
public void get(
8788
@RequestParam("bno") Long bno, @ModelAttribute("criteria") Criteria criteria, Model model) {
8889
LOGGER.info(".get");
89-
model.addAttribute("board", service.get(bno));
90+
BoardVO boardVO = service.get(bno);
91+
model.addAttribute("board", boardVO);
92+
if (boardVO != null) {
93+
// 💡 웹 에디터의 View모드에서 사용할 본문 데이터는 JSON으로 변환해서 받음
94+
model.addAttribute("boardContentJson", GsonHelper.toJson(boardVO.getContent()));
95+
}
9096
}
9197

9298
@PreAuthorize("principal.username == #boardDTO.boardVO.writer")

part-last/my-board-mds/src/test/java/org/fp024/controller/BoardControllerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.fp024.controller;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
5+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
46

57
import java.util.EnumSet;
68
import lombok.extern.slf4j.Slf4j;
@@ -86,6 +88,8 @@ void testGet() throws Exception {
8688
ModelMap getResult =
8789
mockMvc
8890
.perform(MockMvcRequestBuilders.get("/board/get").param("bno", "2"))
91+
.andExpect(status().isOk())
92+
.andExpect(model().attributeExists("board", "boardContentJson"))
8993
.andReturn()
9094
.getModelAndView()
9195
.getModelMap();

0 commit comments

Comments
 (0)