PsHooN7979 07-30
240730 박세훈 게시판 sql 수정
@8fa49ba86840a4c1df82d2815688335cfa639232
 
src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardClassVO.java (added)
+++ src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardClassVO.java
@@ -0,0 +1,34 @@
+package com.takensoft.ai_lms.lms.board.vo;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * @author  : 박세훈
+ * since   : 2024.07.25
+ *
+ * 게시판 class 관련 VO
+ */
+
+
+
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class BoardClassVO {
+
+    // 반 아이디
+    private String sclsId;
+
+    //반 이름
+    private String sclsNm;
+
+    // 게시판 테이블과 연결
+    private List<BoardVO> board;
+}
 
src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardUserVO.java (added)
+++ src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardUserVO.java
@@ -0,0 +1,34 @@
+package com.takensoft.ai_lms.lms.board.vo;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * @author  : 박세훈
+ * since   : 2024.07.25
+ *
+ * 게시판 user 관련 VO
+ */
+
+
+
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class BoardUserVO {
+
+    // 사용자 아이디
+    private String userId;
+
+    // 사용자 이름
+    private String userNm;
+
+    // 반 테이블과 연결
+    private List<BoardClassVO> boardClass;
+}
src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardVO.java
--- src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardVO.java
+++ src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardVO.java
@@ -32,15 +32,15 @@
     // 게시판 아이디
     private String bbsId;
     // 게시판 제목
-    private String bbsTitle;
+    private String bbsTtl;
     // 게시판 카테고리
-    private String bbsCategory;
+    private String bbsCls;
     // 게시판 내용
-    private String bbsContents;
+    private String bbsCnt;
     // 게시판 등록 날짜
-    private String bbsTime;
+    private String bbsTm;
     // 파일 관리 아이디
-    private String fileManageId;
+    private String fileMngId;
     // 반 아이디
     private String sclsId;
 
src/main/resources/mybatis/mapper/lms/board-SQL.xml
--- src/main/resources/mybatis/mapper/lms/board-SQL.xml
+++ src/main/resources/mybatis/mapper/lms/board-SQL.xml
@@ -12,6 +12,23 @@
         <result property="sclsId" column="scls_id"/>
     </resultMap>
 
+    <resultMap id="boardResultMap" type="BoardUserVO">
+        <result property="userId" column="user_id" />
+        <result property="userNm" column="user_nm" />
+        <collection property="boardClass" ofType="BoardClassVO">
+            <id property="sclsId" column="scls_id" />
+            <result property="sclsNm" column="scls_nm" />
+            <collection property="board" ofType="BoardVO" >
+                <id property="bbsId" column="bbs_id"/>
+                <result property="bbsTtl" column="bbs_ttl"/>
+                <result property="bbsCls" column="bbs_cls"/>
+                <result property="bbsCnt" column="bbs_cnt"/>
+                <result property="bbsTm" column="bbs_tm"/>
+                <result property="fileMngId" column="file_mng_id"/>
+                <result property="sclsId" column="scls_id"/>
+            </collection>
+        </collection>
+    </resultMap>
 
     <!--
         작성자 : 박세훈
@@ -51,11 +68,22 @@
         작성일 : 2024.07.25
         내 용 : 게시글 전체 조회
     -->
-    <select id="findAllBoard"  resultMap="boardMap">
-        SELECT *
-        FROM board
-        WHERE scls_id = #{sclsId}
-        ORDER BY bbs_id DESC
+    <select id="findAllBoard"  resultMap="boardResultMap">
+        SELECT  b.bbs_id,
+        b.bbs_ttl,
+        b.bbs_cls,
+        b.bbs_cnt,
+        b.bbs_tm,
+        b.file_mng_id,
+        c.scls_id,
+        c.scls_nm,
+        u.user_id,
+        u.user_nm
+        FROM board b
+        LEFT JOIN class c ON b.scls_id = c.scls_id
+        LEFT JOIN users u ON c.user_id = u.user_id
+        WHERE b.scls_id = #{sclsId}
+        ORDER BY b.bbs_id DESC
         LIMIT #{pageSize} OFFSET #{startIndex}
     </select>
 
@@ -64,10 +92,21 @@
         작성일 : 2024.07.25
         내 용 : 게시글 상세 조회
     -->
-    <select id="findByBoardId" parameterType="BoardVO" resultMap="boardMap">
-        SELECT *
-        FROM board
-        WHERE bbs_id = #{bbsId}
+    <select id="findByBoardId" resultMap="boardResultMap">
+        SELECT  b.bbs_id,
+        b.bbs_ttl,
+        b.bbs_cls,
+        b.bbs_cnt,
+        b.bbs_tm,
+        b.file_mng_id,
+        c.scls_id,
+        c.scls_nm,
+        u.user_id,
+        u.user_nm
+        FROM board b
+        LEFT JOIN class c ON b.scls_id = c.scls_id
+        LEFT JOIN users u ON c.user_id = u.user_id
+        WHERE b.bbs_id = #{bbsId}
         ORDER BY bbs_id DESC
     </select>
 
@@ -76,9 +115,20 @@
         작성일 : 2024.07.26
         내 용 : 게시글 검색
     -->
-    <select id="searchBoard" parameterType="BoardVO" resultMap="boardMap">
-        SELECT *
-        FROM board
+    <select id="searchBoard" resultMap="boardResultMap">
+        SELECT  b.bbs_id,
+        b.bbs_ttl,
+        b.bbs_cls,
+        b.bbs_cnt,
+        b.bbs_tm,
+        b.file_mng_id,
+        c.scls_id,
+        c.scls_nm,
+        u.user_id,
+        u.user_nm
+        FROM board b
+        LEFT JOIN class c ON b.scls_id = c.scls_id
+        LEFT JOIN users u ON c.user_id = u.user_id
         WHERE 1 = 1
         <if test="option != null and keyword != null">
             <choose>
@@ -122,4 +172,5 @@
         DELETE FROM board WHERE bbs_id = #{bbsId}
     </delete>
 
-</mapper>
(파일 끝에 줄바꿈 문자 없음)
+</mapper>
+
Add a comment
List