PsHooN7979 07-26
240726 박세훈 게시판 CRUD
@b9765fce3a6429ceef92b31970d9fca78aef1746
 
src/main/java/com/takensoft/ai_lms/lms/board/dao/BoardDAO.java (added)
+++ src/main/java/com/takensoft/ai_lms/lms/board/dao/BoardDAO.java
@@ -0,0 +1,38 @@
+package com.takensoft.ai_lms.lms.board.dao;
+
+
+import com.takensoft.ai_lms.lms.board.vo.BoardVO;
+import org.egovframe.rte.psl.dataaccess.mapper.Mapper;
+
+import java.util.HashMap;
+import java.util.List;
+
+
+/**
+ * @author  : 박세훈
+ * since   : 2024.07.25
+ *
+ * 게시판 관련 Mapper
+ */
+
+@Mapper("boardDAO")
+public interface BoardDAO {
+    // 게시글 등록
+    int insertBoard(BoardVO boardVO) throws Exception;
+
+    // 게시글 전체 조회
+    List<HashMap<String, Object>> findAllBoard(HashMap<String, Object> params) throws Exception;
+
+    // 게시물 수 조회
+    int boardCount(HashMap<String, Object> params) throws Exception;
+
+    // 게시글 상세 조회
+    List<HashMap<String, Object>> findByBoardId(HashMap<String, Object> params) throws Exception;
+
+    // 게시글 수정
+    int updateBoard(BoardVO boardVO) throws Exception;
+
+    // 게시글 삭제
+    int deleteBoard(String bbsId) throws Exception;
+
+}
 
src/main/java/com/takensoft/ai_lms/lms/board/service/BoardService.java (added)
+++ src/main/java/com/takensoft/ai_lms/lms/board/service/BoardService.java
@@ -0,0 +1,34 @@
+package com.takensoft.ai_lms.lms.board.service;
+
+import com.takensoft.ai_lms.lms.board.vo.BoardVO;
+
+import java.util.HashMap;
+import java.util.List;
+
+
+/**
+ * @author  : 박세훈
+ * since   : 2024.07.25
+ *
+ * 게시판 관련 Service
+ */
+public interface BoardService {
+
+    // 게시글 등록
+    int insertBoard(BoardVO boardVO) throws Exception;
+
+    // 게시글 전체 조회
+    List<HashMap<String, Object>> findAllBoard(HashMap<String, Object> params) throws Exception;
+
+    // 게시물 수 조회
+    int boardCount(HashMap<String, Object> params) throws Exception;
+
+    // 게시글 상세 조회
+    List<HashMap<String, Object>> findByBoardId(HashMap<String, Object> params) throws Exception;
+
+    // 게시글 수정
+    int updateBoard(BoardVO boardVO) throws Exception;
+
+    // 게시글 삭제
+    int deleteBoard(String bbsId) throws Exception;
+}
 
src/main/java/com/takensoft/ai_lms/lms/board/service/impl/BoardServiceImpl.java (added)
+++ src/main/java/com/takensoft/ai_lms/lms/board/service/impl/BoardServiceImpl.java
@@ -0,0 +1,67 @@
+package com.takensoft.ai_lms.lms.board.service.impl;
+
+import com.takensoft.ai_lms.lms.board.dao.BoardDAO;
+import com.takensoft.ai_lms.lms.board.service.BoardService;
+import com.takensoft.ai_lms.lms.board.vo.BoardVO;
+import lombok.RequiredArgsConstructor;
+import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+
+@Service("boardService")
+@RequiredArgsConstructor
+public class BoardServiceImpl extends EgovAbstractServiceImpl implements BoardService {
+
+    private final BoardDAO boardDAO;
+
+
+    // 게시글 등록
+    @Override
+    public int insertBoard(BoardVO boardVO) throws Exception {
+        return boardDAO.insertBoard(boardVO);
+    }
+    // 게시글 전체 조회
+    @Override
+    public List<HashMap<String, Object>> findAllBoard(HashMap<String, Object> params) throws Exception {
+        int page = Integer.parseInt(params.get("page").toString());
+        int pageSize = Integer.parseInt(params.get("pageSize").toString());
+
+        // 조회를 위한 startIndex 계산
+        int startIndex = (page - 1) * pageSize;
+        params.put("startIndex", startIndex);
+        params.put("pageSize", pageSize);
+        System.out.println(startIndex);
+        return boardDAO.findAllBoard(params);
+    }
+
+    // 전체 게시물 수 조회
+    @Override
+    public int boardCount(HashMap<String, Object> params) throws Exception {
+        return boardDAO.boardCount(params);
+    }
+
+
+    // 게시글 상세 조회
+    @Override
+    public List<HashMap<String, Object>> findByBoardId(HashMap<String, Object> params) throws Exception {
+        return boardDAO.findByBoardId(params);
+    }
+
+    // 게시글 수정
+    @Override
+    public int updateBoard(BoardVO boardVO) throws Exception {
+        return boardDAO.updateBoard(boardVO);
+    }
+
+    // 게시글 삭제
+    @Override
+    public int deleteBoard(String bbsId) throws Exception{
+        return boardDAO.deleteBoard(bbsId);
+    }
+
+
+
+
+}
 
src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardVO.java (added)
+++ src/main/java/com/takensoft/ai_lms/lms/board/vo/BoardVO.java
@@ -0,0 +1,50 @@
+package com.takensoft.ai_lms.lms.board.vo;
+
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springmodules.validation.bean.conf.loader.annotation.handler.MaxSize;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+
+
+/**
+ * @author  : 박세훈
+ * since   : 2024.07.25
+ *
+ * 게시판 관련 VO
+ */
+
+
+
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class BoardVO {
+
+    // 게시판 아이디
+    private String bbsId;
+    // 게시판 제목
+    private String bbsTitle;
+    // 게시판 카테고리
+    private String bbsCategory;
+    // 게시판 내용
+    private String bbsContents;
+    // 게시판 등록 날짜
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
+    private LocalDate bbsTime;
+    // 파일 관리 아이디
+    private String fileManageId;
+    // 반 아이디
+    private String sclsId;
+
+
+}
 
src/main/java/com/takensoft/ai_lms/lms/board/web/BoardController.java (added)
+++ src/main/java/com/takensoft/ai_lms/lms/board/web/BoardController.java
@@ -0,0 +1,132 @@
+package com.takensoft.ai_lms.lms.board.web;
+
+
+import com.takensoft.ai_lms.lms.board.service.BoardService;
+import com.takensoft.ai_lms.lms.board.vo.BoardVO;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author  : 박세훈
+ * since   : 2024.07.25
+ * 게시판 관련 Controller
+ */
+@RestController
+//@Slf4j
+@RequiredArgsConstructor
+@RequestMapping(value = "/board")
+public class BoardController {
+
+    private final BoardService boardService;
+
+    /**
+     * @author 박세훈
+     * @since 2024.07.25
+     *
+     * 게시글 등록
+     */
+    @PostMapping("/insert.json")
+    public String insertBoard(@RequestBody BoardVO boardVO) throws Exception{
+        try {
+            int result = boardService.insertBoard(boardVO);
+            if (result > 0 ) {
+                return "success";
+            } else {
+                return "fail";
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "Error";
+        }
+    }
+
+
+    /**
+     * @author 박세훈
+     * @since 2024.07.25
+     *
+     * 게시글 전체 조회
+     */
+    @PostMapping("/findAll.json")
+    public ResponseEntity<?> findAllBoard(@RequestBody HashMap<String, Object> params) throws Exception {
+        HashMap<String, Object> result = new HashMap<>();
+
+        // 페이지 번호와 페이지 크기를 파라미터로 전달
+        int page = Integer.parseInt(params.get("page").toString());
+        int pageSize = Integer.parseInt(params.get("pageSize").toString());
+
+
+        // 전체 게시물 수 조회 및 추가
+        int totalBoard = boardService.boardCount(params);
+        result.put("totalBoard", totalBoard);
+        result.put("list", boardService.findAllBoard(params));
+
+
+        return new ResponseEntity<>(result, HttpStatus.OK);
+    }
+
+    /**
+     * @author 박세훈
+     * @since 2024.07.25
+     *
+     * 게시글 상세 조회
+     */
+
+    @PostMapping("/find.json")
+    public ResponseEntity<?> findByBoardId(@RequestBody HashMap<String, Object> params) throws Exception {
+        HashMap<String, Object> result = new HashMap<>();
+
+        result.put("list", boardService.findByBoardId(params));
+        return new ResponseEntity<>(result, HttpStatus.OK);
+    }
+    /**
+     * @author 박세훈
+     * @since 2024.07.25
+     *
+     * 게시글 수정
+     */
+    @PutMapping("/update.json")
+    public String updateBoard(@RequestBody BoardVO boardVO) throws Exception {
+        try {
+            int result = boardService.updateBoard(boardVO);
+            if (result > 0 ) {
+                return "success";
+            } else {
+                return "fail";
+            }
+        } catch (Exception e){
+            e.printStackTrace();
+            return "Error";
+        }
+    }
+    /**
+     * @author 박세훈
+     * @since 2024.07.25
+     *
+     * 게시글 삭제
+     */
+    @DeleteMapping("/delete.json")
+    public String deleteBoard(@RequestBody Map<String, String> request) throws Exception {
+        try{
+            String bbsId = request.get("bbsId");
+            int result = boardService.deleteBoard(bbsId);
+            if (result > 0 ) {
+                return "success";
+            } else {
+                return "fail";
+            }
+        } catch (Exception e){
+            e.printStackTrace();
+            return "Error";
+        }
+    }
+
+
+
+}
 
src/main/resources/mybatis/mapper/lms/board-SQL.xml (added)
+++ src/main/resources/mybatis/mapper/lms/board-SQL.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.takensoft.ai_lms.lms.board.dao.BoardDAO">
+    <!--
+        작 성 자 : 박민혁
+        작 성 일 : 2024.07.25
+        내   용 : 경로 생성을 위해 만들어 놓은 xml,
+        CRUD를 이용하는데 삭제하거나 수정해서 사용해주세요
+    -->
+    <resultMap id="boardMap" type="BoardVO">
+        <result property="bbsId" column="bbs_id"/>
+        <result property="bbsTitle" column="bbs_ttl"/>
+        <result property="bbsCategory" column="bbs_cls"/>
+        <result property="bbsContents" column="bbs_cnt"/>
+        <result property="bbsTime" column="bbs_tm"/>
+        <result property="fileManageId" column="file_mng_id"/>
+        <result property="sclsId" column="scls_id"/>
+    </resultMap>
+
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.07.25
+        내 용 : 게시글 등록 관련
+    -->
+    <insert id="insertBoard" parameterType="BoardVO">
+        INSERT INTO board(bbs_id, bbs_ttl, bbs_cls, bbs_cnt,bbs_tm,  file_mng_id, scls_id)
+        VALUES ( #{bbsId}, #{bbsTitle}, #{bbsCategory}, #{bbsContents}, now(), #{fileManageId}, #{sclsId});
+    </insert>
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.07.25
+        내 용 : 전체 게시물 수 조회
+    -->
+    <select id="boardCount" resultType="Integer">
+        SELECT COUNT(*)
+        FROM board
+        WHERE scls_id = #{sclsId}
+    </select>
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.07.25
+        내 용 : 게시글 전체 조회
+    -->
+    <select id="findAllBoard"  resultMap="boardMap">
+        SELECT bbs_id, bbs_ttl, bbs_cls, bbs_cnt,bbs_tm, file_mng_id, scls_id
+        FROM board
+        WHERE scls_id = #{sclsId}
+        ORDER BY bbs_id DESC
+        LIMIT #{pageSize} OFFSET #{startIndex}
+    </select>
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.07.25
+        내 용 : 게시글 상세 조회
+    -->
+    <select id="findByBoardId" parameterType="BoardVO" resultMap="boardMap">
+        SELECT bbs_id, bbs_ttl, bbs_cls, bbs_cnt, file_mng_id
+        FROM board
+        WHERE bbs_id = #{bbsId}
+        ORDER BY bbs_id DESC
+    </select>
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.07.25
+        내 용 : 게시글 수정
+    -->
+    <update id="updateBoard" parameterType="BoardVO">
+        UPDATE board
+        SET bbs_ttl = #{bbsTitle},
+            bbs_cls = #{bbsCategory},
+            bbs_cnt = #{bbsContents},
+            bbs_tm = now(),
+            file_mng_id = #{fileManageId}
+        WHERE
+            bbs_id = #{bbsId}
+    </update>
+
+    <!--
+        작성자 : 박세훈
+        작성일 : 2024.07.25
+        내 용 : 게시글 삭제
+    -->
+    <delete id="deleteBoard" parameterType="String">
+        DELETE FROM board WHERE bbs_id = #{bbsId}
+    </delete>
+
+</mapper>(파일 끝에 줄바꿈 문자 없음)
Add a comment
List