PsHooN7979 07-30
240726 박세훈 게시판 sql 수정
@0b6351dcbee979c5bd353784f397c48106df6e3e
 
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/java/com/takensoft/ai_lms/lms/survey/web/SurveyController.java
--- src/main/java/com/takensoft/ai_lms/lms/survey/web/SurveyController.java
+++ src/main/java/com/takensoft/ai_lms/lms/survey/web/SurveyController.java
@@ -23,6 +23,7 @@
 
     private final SurveyService surveyService;
 
+    // 설문 조사 등록
     @PostMapping("/insert.json")
     public String insertSurvey(@RequestBody SurveyVO surveyVO) throws Exception {
         try {
@@ -37,12 +38,13 @@
         }
     }
 
+    // 설문 조사 조회
     @GetMapping("/list.json")
     public List<SurveyVO> surveyList(SurveyVO surveyVO) throws Exception {
         return surveyService.surveyList(surveyVO);
     }
 
-
+    // 설문 조사 수정
     @PutMapping("/update.json")
     public String updateSurvey (@RequestBody SurveyVO surveyVO) throws Exception {
         try {
@@ -58,6 +60,7 @@
     }
 
 
+    // 설문 조사 삭제
     @DeleteMapping("/delete.json")
     public String deleteSurvey (@RequestBody Map<String, String> request) throws Exception {
         try {
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,11 +92,21 @@
         작성일 : 2024.07.25
         내 용 : 게시글 상세 조회
     -->
-    <select id="findByBoardId" parameterType="BoardVO" resultMap="boardMap">
-        SELECT *
-        FROM board
-        WHERE bbs_id = #{bbsId}
-        ORDER BY bbs_id DESC
+    <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}
     </select>
 
     <!--
@@ -122,4 +160,4 @@
         DELETE FROM board WHERE bbs_id = #{bbsId}
     </delete>
 
-</mapper>
(파일 끝에 줄바꿈 문자 없음)
+</mapper>
Add a comment
List