PsHooN7979 07-26
240726 박세훈 게시글 검색 기능 추가
@834c6447b6364b23d2a2c5fdacf30e4a109c63e5
src/main/java/com/takensoft/ai_lms/lms/board/dao/BoardDAO.java
--- src/main/java/com/takensoft/ai_lms/lms/board/dao/BoardDAO.java
+++ src/main/java/com/takensoft/ai_lms/lms/board/dao/BoardDAO.java
@@ -35,4 +35,8 @@
     // 게시글 삭제
     int deleteBoard(String bbsId) throws Exception;
 
+    // 게시글 검색
+    List<HashMap<String, Object>> searchBoard(HashMap<String, Object> params) throws Exception;
+
+
 }
src/main/java/com/takensoft/ai_lms/lms/board/service/BoardService.java
--- src/main/java/com/takensoft/ai_lms/lms/board/service/BoardService.java
+++ src/main/java/com/takensoft/ai_lms/lms/board/service/BoardService.java
@@ -31,4 +31,7 @@
 
     // 게시글 삭제
     int deleteBoard(String bbsId) throws Exception;
+
+    // 게시글 검색
+    List<HashMap<String, Object>> searchBoard(HashMap<String, Object> params) throws Exception;
 }
src/main/java/com/takensoft/ai_lms/lms/board/service/impl/BoardServiceImpl.java
--- src/main/java/com/takensoft/ai_lms/lms/board/service/impl/BoardServiceImpl.java
+++ src/main/java/com/takensoft/ai_lms/lms/board/service/impl/BoardServiceImpl.java
@@ -65,6 +65,12 @@
         return boardDAO.deleteBoard(bbsId);
     }
 
+    // 게시글 검색
+    @Override
+    public List<HashMap<String, Object>> searchBoard(HashMap<String, Object> params) throws Exception {
+        return boardDAO.searchBoard(params);
+    }
+
 
 
 
src/main/java/com/takensoft/ai_lms/lms/board/web/BoardController.java
--- src/main/java/com/takensoft/ai_lms/lms/board/web/BoardController.java
+++ src/main/java/com/takensoft/ai_lms/lms/board/web/BoardController.java
@@ -10,6 +10,7 @@
 import org.springframework.web.bind.annotation.*;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -127,6 +128,22 @@
         }
     }
 
+    /**
+     * @author 박세훈
+     * @since 2024.07.26
+     *
+     * 게시글 검색
+     */
+
+    @PostMapping("/search.json")
+    public ResponseEntity<?> searchBoard(@RequestBody HashMap<String, Object> params) throws Exception {
+        HashMap<String, Object> result = new HashMap<>();
+
+        List<HashMap<String, Object>> boardList = boardService.searchBoard(params);
+        result.put("list", boardList);
+        return new ResponseEntity<>(result, HttpStatus.OK);
+    }
+
 
 
 }
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
@@ -45,7 +45,7 @@
         내 용 : 게시글 전체 조회
     -->
     <select id="findAllBoard"  resultMap="boardMap">
-        SELECT bbs_id, bbs_ttl, bbs_cls, bbs_cnt,bbs_tm, file_mng_id, scls_id
+        SELECT *
         FROM board
         WHERE scls_id = #{sclsId}
         ORDER BY bbs_id DESC
@@ -58,7 +58,7 @@
         내 용 : 게시글 상세 조회
     -->
     <select id="findByBoardId" parameterType="BoardVO" resultMap="boardMap">
-        SELECT bbs_id, bbs_ttl, bbs_cls, bbs_cnt,bbs_tm, file_mng_id
+        SELECT *
         FROM board
         WHERE bbs_id = #{bbsId}
         ORDER BY bbs_id DESC
@@ -66,6 +66,32 @@
 
     <!--
         작성자 : 박세훈
+        작성일 : 2024.07.26
+        내 용 : 게시글 검색
+    -->
+    <select id="searchBoard" parameterType="BoardVO" resultMap="boardMap">
+        SELECT *
+        FROM board
+        WHERE 1 = 1
+        <if test="option != null and keyword != null">
+            <choose>
+                <when test="option == 'bbsTitle'">
+                    AND bbs_ttl LIKE CONCAT('%', #{keyword}, '%')
+                </when>
+                <when test="option == 'bbsCategory'">
+                    AND bbs_cls LIKE CONCAT('%', #{keyword}, '%')
+                </when>
+                <otherwise>
+                    AND bbs_cnt LIKE CONCAT('%', #{keyword}, '%')
+                </otherwise>
+            </choose>
+        </if>
+        ORDER BY bbs_id DESC
+        LIMIT #{pageSize} OFFSET #{startIndex}
+    </select>
+
+    <!--
+        작성자 : 박세훈
         작성일 : 2024.07.25
         내 용 : 게시글 수정
     -->
Add a comment
List