PsHooN7979
07-26
240726 박세훈 게시판 CRUD
@b9765fce3a6429ceef92b31970d9fca78aef1746
+++ src/main/java/com/takensoft/ai_lms/lms/board/dao/BoardDAO.java
... | ... | @@ -0,0 +1,38 @@ |
1 | +package com.takensoft.ai_lms.lms.board.dao; | |
2 | + | |
3 | + | |
4 | +import com.takensoft.ai_lms.lms.board.vo.BoardVO; | |
5 | +import org.egovframe.rte.psl.dataaccess.mapper.Mapper; | |
6 | + | |
7 | +import java.util.HashMap; | |
8 | +import java.util.List; | |
9 | + | |
10 | + | |
11 | +/** | |
12 | + * @author : 박세훈 | |
13 | + * since : 2024.07.25 | |
14 | + * | |
15 | + * 게시판 관련 Mapper | |
16 | + */ | |
17 | + | |
18 | +@Mapper("boardDAO") | |
19 | +public interface BoardDAO { | |
20 | + // 게시글 등록 | |
21 | + int insertBoard(BoardVO boardVO) throws Exception; | |
22 | + | |
23 | + // 게시글 전체 조회 | |
24 | + List<HashMap<String, Object>> findAllBoard(HashMap<String, Object> params) throws Exception; | |
25 | + | |
26 | + // 게시물 수 조회 | |
27 | + int boardCount(HashMap<String, Object> params) throws Exception; | |
28 | + | |
29 | + // 게시글 상세 조회 | |
30 | + List<HashMap<String, Object>> findByBoardId(HashMap<String, Object> params) throws Exception; | |
31 | + | |
32 | + // 게시글 수정 | |
33 | + int updateBoard(BoardVO boardVO) throws Exception; | |
34 | + | |
35 | + // 게시글 삭제 | |
36 | + int deleteBoard(String bbsId) throws Exception; | |
37 | + | |
38 | +} |
+++ src/main/java/com/takensoft/ai_lms/lms/board/service/BoardService.java
... | ... | @@ -0,0 +1,34 @@ |
1 | +package com.takensoft.ai_lms.lms.board.service; | |
2 | + | |
3 | +import com.takensoft.ai_lms.lms.board.vo.BoardVO; | |
4 | + | |
5 | +import java.util.HashMap; | |
6 | +import java.util.List; | |
7 | + | |
8 | + | |
9 | +/** | |
10 | + * @author : 박세훈 | |
11 | + * since : 2024.07.25 | |
12 | + * | |
13 | + * 게시판 관련 Service | |
14 | + */ | |
15 | +public interface BoardService { | |
16 | + | |
17 | + // 게시글 등록 | |
18 | + int insertBoard(BoardVO boardVO) throws Exception; | |
19 | + | |
20 | + // 게시글 전체 조회 | |
21 | + List<HashMap<String, Object>> findAllBoard(HashMap<String, Object> params) throws Exception; | |
22 | + | |
23 | + // 게시물 수 조회 | |
24 | + int boardCount(HashMap<String, Object> params) throws Exception; | |
25 | + | |
26 | + // 게시글 상세 조회 | |
27 | + List<HashMap<String, Object>> findByBoardId(HashMap<String, Object> params) throws Exception; | |
28 | + | |
29 | + // 게시글 수정 | |
30 | + int updateBoard(BoardVO boardVO) throws Exception; | |
31 | + | |
32 | + // 게시글 삭제 | |
33 | + int deleteBoard(String bbsId) throws Exception; | |
34 | +} |
+++ src/main/java/com/takensoft/ai_lms/lms/board/service/impl/BoardServiceImpl.java
... | ... | @@ -0,0 +1,67 @@ |
1 | +package com.takensoft.ai_lms.lms.board.service.impl; | |
2 | + | |
3 | +import com.takensoft.ai_lms.lms.board.dao.BoardDAO; | |
4 | +import com.takensoft.ai_lms.lms.board.service.BoardService; | |
5 | +import com.takensoft.ai_lms.lms.board.vo.BoardVO; | |
6 | +import lombok.RequiredArgsConstructor; | |
7 | +import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl; | |
8 | +import org.springframework.stereotype.Service; | |
9 | + | |
10 | +import java.util.HashMap; | |
11 | +import java.util.List; | |
12 | + | |
13 | +@Service("boardService") | |
14 | +@RequiredArgsConstructor | |
15 | +public class BoardServiceImpl extends EgovAbstractServiceImpl implements BoardService { | |
16 | + | |
17 | + private final BoardDAO boardDAO; | |
18 | + | |
19 | + | |
20 | + // 게시글 등록 | |
21 | + @Override | |
22 | + public int insertBoard(BoardVO boardVO) throws Exception { | |
23 | + return boardDAO.insertBoard(boardVO); | |
24 | + } | |
25 | + // 게시글 전체 조회 | |
26 | + @Override | |
27 | + public List<HashMap<String, Object>> findAllBoard(HashMap<String, Object> params) throws Exception { | |
28 | + int page = Integer.parseInt(params.get("page").toString()); | |
29 | + int pageSize = Integer.parseInt(params.get("pageSize").toString()); | |
30 | + | |
31 | + // 조회를 위한 startIndex 계산 | |
32 | + int startIndex = (page - 1) * pageSize; | |
33 | + params.put("startIndex", startIndex); | |
34 | + params.put("pageSize", pageSize); | |
35 | + System.out.println(startIndex); | |
36 | + return boardDAO.findAllBoard(params); | |
37 | + } | |
38 | + | |
39 | + // 전체 게시물 수 조회 | |
40 | + @Override | |
41 | + public int boardCount(HashMap<String, Object> params) throws Exception { | |
42 | + return boardDAO.boardCount(params); | |
43 | + } | |
44 | + | |
45 | + | |
46 | + // 게시글 상세 조회 | |
47 | + @Override | |
48 | + public List<HashMap<String, Object>> findByBoardId(HashMap<String, Object> params) throws Exception { | |
49 | + return boardDAO.findByBoardId(params); | |
50 | + } | |
51 | + | |
52 | + // 게시글 수정 | |
53 | + @Override | |
54 | + public int updateBoard(BoardVO boardVO) throws Exception { | |
55 | + return boardDAO.updateBoard(boardVO); | |
56 | + } | |
57 | + | |
58 | + // 게시글 삭제 | |
59 | + @Override | |
60 | + public int deleteBoard(String bbsId) throws Exception{ | |
61 | + return boardDAO.deleteBoard(bbsId); | |
62 | + } | |
63 | + | |
64 | + | |
65 | + | |
66 | + | |
67 | +} |
+++ src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardVO.java
... | ... | @@ -0,0 +1,50 @@ |
1 | +package com.takensoft.ai_lms.lms.board.vo; | |
2 | + | |
3 | + | |
4 | +import com.fasterxml.jackson.annotation.JsonFormat; | |
5 | +import lombok.AllArgsConstructor; | |
6 | +import lombok.Getter; | |
7 | +import lombok.NoArgsConstructor; | |
8 | +import lombok.Setter; | |
9 | +import org.springframework.format.annotation.DateTimeFormat; | |
10 | +import org.springmodules.validation.bean.conf.loader.annotation.handler.MaxSize; | |
11 | + | |
12 | +import java.time.LocalDate; | |
13 | +import java.time.LocalDateTime; | |
14 | + | |
15 | + | |
16 | + | |
17 | +/** | |
18 | + * @author : 박세훈 | |
19 | + * since : 2024.07.25 | |
20 | + * | |
21 | + * 게시판 관련 VO | |
22 | + */ | |
23 | + | |
24 | + | |
25 | + | |
26 | +@Getter | |
27 | +@Setter | |
28 | +@AllArgsConstructor | |
29 | +@NoArgsConstructor | |
30 | +public class BoardVO { | |
31 | + | |
32 | + // 게시판 아이디 | |
33 | + private String bbsId; | |
34 | + // 게시판 제목 | |
35 | + private String bbsTitle; | |
36 | + // 게시판 카테고리 | |
37 | + private String bbsCategory; | |
38 | + // 게시판 내용 | |
39 | + private String bbsContents; | |
40 | + // 게시판 등록 날짜 | |
41 | + @DateTimeFormat(pattern = "yyyy-MM-dd") | |
42 | + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") | |
43 | + private LocalDate bbsTime; | |
44 | + // 파일 관리 아이디 | |
45 | + private String fileManageId; | |
46 | + // 반 아이디 | |
47 | + private String sclsId; | |
48 | + | |
49 | + | |
50 | +} |
+++ src/main/java/com/takensoft/ai_lms/lms/board/web/BoardController.java
... | ... | @@ -0,0 +1,132 @@ |
1 | +package com.takensoft.ai_lms.lms.board.web; | |
2 | + | |
3 | + | |
4 | +import com.takensoft.ai_lms.lms.board.service.BoardService; | |
5 | +import com.takensoft.ai_lms.lms.board.vo.BoardVO; | |
6 | +import lombok.RequiredArgsConstructor; | |
7 | +import lombok.extern.slf4j.Slf4j; | |
8 | +import org.springframework.http.HttpStatus; | |
9 | +import org.springframework.http.ResponseEntity; | |
10 | +import org.springframework.web.bind.annotation.*; | |
11 | + | |
12 | +import java.util.HashMap; | |
13 | +import java.util.Map; | |
14 | + | |
15 | +/** | |
16 | + * @author : 박세훈 | |
17 | + * since : 2024.07.25 | |
18 | + * 게시판 관련 Controller | |
19 | + */ | |
20 | +@RestController | |
21 | +//@Slf4j | |
22 | +@RequiredArgsConstructor | |
23 | +@RequestMapping(value = "/board") | |
24 | +public class BoardController { | |
25 | + | |
26 | + private final BoardService boardService; | |
27 | + | |
28 | + /** | |
29 | + * @author 박세훈 | |
30 | + * @since 2024.07.25 | |
31 | + * | |
32 | + * 게시글 등록 | |
33 | + */ | |
34 | + @PostMapping("/insert.json") | |
35 | + public String insertBoard(@RequestBody BoardVO boardVO) throws Exception{ | |
36 | + try { | |
37 | + int result = boardService.insertBoard(boardVO); | |
38 | + if (result > 0 ) { | |
39 | + return "success"; | |
40 | + } else { | |
41 | + return "fail"; | |
42 | + } | |
43 | + } catch (Exception e) { | |
44 | + e.printStackTrace(); | |
45 | + return "Error"; | |
46 | + } | |
47 | + } | |
48 | + | |
49 | + | |
50 | + /** | |
51 | + * @author 박세훈 | |
52 | + * @since 2024.07.25 | |
53 | + * | |
54 | + * 게시글 전체 조회 | |
55 | + */ | |
56 | + @PostMapping("/findAll.json") | |
57 | + public ResponseEntity<?> findAllBoard(@RequestBody HashMap<String, Object> params) throws Exception { | |
58 | + HashMap<String, Object> result = new HashMap<>(); | |
59 | + | |
60 | + // 페이지 번호와 페이지 크기를 파라미터로 전달 | |
61 | + int page = Integer.parseInt(params.get("page").toString()); | |
62 | + int pageSize = Integer.parseInt(params.get("pageSize").toString()); | |
63 | + | |
64 | + | |
65 | + // 전체 게시물 수 조회 및 추가 | |
66 | + int totalBoard = boardService.boardCount(params); | |
67 | + result.put("totalBoard", totalBoard); | |
68 | + result.put("list", boardService.findAllBoard(params)); | |
69 | + | |
70 | + | |
71 | + return new ResponseEntity<>(result, HttpStatus.OK); | |
72 | + } | |
73 | + | |
74 | + /** | |
75 | + * @author 박세훈 | |
76 | + * @since 2024.07.25 | |
77 | + * | |
78 | + * 게시글 상세 조회 | |
79 | + */ | |
80 | + | |
81 | + @PostMapping("/find.json") | |
82 | + public ResponseEntity<?> findByBoardId(@RequestBody HashMap<String, Object> params) throws Exception { | |
83 | + HashMap<String, Object> result = new HashMap<>(); | |
84 | + | |
85 | + result.put("list", boardService.findByBoardId(params)); | |
86 | + return new ResponseEntity<>(result, HttpStatus.OK); | |
87 | + } | |
88 | + /** | |
89 | + * @author 박세훈 | |
90 | + * @since 2024.07.25 | |
91 | + * | |
92 | + * 게시글 수정 | |
93 | + */ | |
94 | + @PutMapping("/update.json") | |
95 | + public String updateBoard(@RequestBody BoardVO boardVO) throws Exception { | |
96 | + try { | |
97 | + int result = boardService.updateBoard(boardVO); | |
98 | + if (result > 0 ) { | |
99 | + return "success"; | |
100 | + } else { | |
101 | + return "fail"; | |
102 | + } | |
103 | + } catch (Exception e){ | |
104 | + e.printStackTrace(); | |
105 | + return "Error"; | |
106 | + } | |
107 | + } | |
108 | + /** | |
109 | + * @author 박세훈 | |
110 | + * @since 2024.07.25 | |
111 | + * | |
112 | + * 게시글 삭제 | |
113 | + */ | |
114 | + @DeleteMapping("/delete.json") | |
115 | + public String deleteBoard(@RequestBody Map<String, String> request) throws Exception { | |
116 | + try{ | |
117 | + String bbsId = request.get("bbsId"); | |
118 | + int result = boardService.deleteBoard(bbsId); | |
119 | + if (result > 0 ) { | |
120 | + return "success"; | |
121 | + } else { | |
122 | + return "fail"; | |
123 | + } | |
124 | + } catch (Exception e){ | |
125 | + e.printStackTrace(); | |
126 | + return "Error"; | |
127 | + } | |
128 | + } | |
129 | + | |
130 | + | |
131 | + | |
132 | +} |
+++ src/main/resources/mybatis/mapper/lms/board-SQL.xml
... | ... | @@ -0,0 +1,92 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
3 | +<mapper namespace="com.takensoft.ai_lms.lms.board.dao.BoardDAO"> | |
4 | + <!-- | |
5 | + 작 성 자 : 박민혁 | |
6 | + 작 성 일 : 2024.07.25 | |
7 | + 내 용 : 경로 생성을 위해 만들어 놓은 xml, | |
8 | + CRUD를 이용하는데 삭제하거나 수정해서 사용해주세요 | |
9 | + --> | |
10 | + <resultMap id="boardMap" type="BoardVO"> | |
11 | + <result property="bbsId" column="bbs_id"/> | |
12 | + <result property="bbsTitle" column="bbs_ttl"/> | |
13 | + <result property="bbsCategory" column="bbs_cls"/> | |
14 | + <result property="bbsContents" column="bbs_cnt"/> | |
15 | + <result property="bbsTime" column="bbs_tm"/> | |
16 | + <result property="fileManageId" column="file_mng_id"/> | |
17 | + <result property="sclsId" column="scls_id"/> | |
18 | + </resultMap> | |
19 | + | |
20 | + | |
21 | + <!-- | |
22 | + 작성자 : 박세훈 | |
23 | + 작성일 : 2024.07.25 | |
24 | + 내 용 : 게시글 등록 관련 | |
25 | + --> | |
26 | + <insert id="insertBoard" parameterType="BoardVO"> | |
27 | + INSERT INTO board(bbs_id, bbs_ttl, bbs_cls, bbs_cnt,bbs_tm, file_mng_id, scls_id) | |
28 | + VALUES ( #{bbsId}, #{bbsTitle}, #{bbsCategory}, #{bbsContents}, now(), #{fileManageId}, #{sclsId}); | |
29 | + </insert> | |
30 | + | |
31 | + <!-- | |
32 | + 작성자 : 박세훈 | |
33 | + 작성일 : 2024.07.25 | |
34 | + 내 용 : 전체 게시물 수 조회 | |
35 | + --> | |
36 | + <select id="boardCount" resultType="Integer"> | |
37 | + SELECT COUNT(*) | |
38 | + FROM board | |
39 | + WHERE scls_id = #{sclsId} | |
40 | + </select> | |
41 | + | |
42 | + <!-- | |
43 | + 작성자 : 박세훈 | |
44 | + 작성일 : 2024.07.25 | |
45 | + 내 용 : 게시글 전체 조회 | |
46 | + --> | |
47 | + <select id="findAllBoard" resultMap="boardMap"> | |
48 | + SELECT bbs_id, bbs_ttl, bbs_cls, bbs_cnt,bbs_tm, file_mng_id, scls_id | |
49 | + FROM board | |
50 | + WHERE scls_id = #{sclsId} | |
51 | + ORDER BY bbs_id DESC | |
52 | + LIMIT #{pageSize} OFFSET #{startIndex} | |
53 | + </select> | |
54 | + | |
55 | + <!-- | |
56 | + 작성자 : 박세훈 | |
57 | + 작성일 : 2024.07.25 | |
58 | + 내 용 : 게시글 상세 조회 | |
59 | + --> | |
60 | + <select id="findByBoardId" parameterType="BoardVO" resultMap="boardMap"> | |
61 | + SELECT bbs_id, bbs_ttl, bbs_cls, bbs_cnt, file_mng_id | |
62 | + FROM board | |
63 | + WHERE bbs_id = #{bbsId} | |
64 | + ORDER BY bbs_id DESC | |
65 | + </select> | |
66 | + | |
67 | + <!-- | |
68 | + 작성자 : 박세훈 | |
69 | + 작성일 : 2024.07.25 | |
70 | + 내 용 : 게시글 수정 | |
71 | + --> | |
72 | + <update id="updateBoard" parameterType="BoardVO"> | |
73 | + UPDATE board | |
74 | + SET bbs_ttl = #{bbsTitle}, | |
75 | + bbs_cls = #{bbsCategory}, | |
76 | + bbs_cnt = #{bbsContents}, | |
77 | + bbs_tm = now(), | |
78 | + file_mng_id = #{fileManageId} | |
79 | + WHERE | |
80 | + bbs_id = #{bbsId} | |
81 | + </update> | |
82 | + | |
83 | + <!-- | |
84 | + 작성자 : 박세훈 | |
85 | + 작성일 : 2024.07.25 | |
86 | + 내 용 : 게시글 삭제 | |
87 | + --> | |
88 | + <delete id="deleteBoard" parameterType="String"> | |
89 | + DELETE FROM board WHERE bbs_id = #{bbsId} | |
90 | + </delete> | |
91 | + | |
92 | +</mapper>(파일 끝에 줄바꿈 문자 없음) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?