Notice
Recent Posts
Recent Comments
Link
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

BDao 본문

JSP/BBS

BDao

GAWON 2023. 6. 9. 17:47
package org.joonzis.ex;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.joonzis.mybatis.DBService;

public class BDao {
   private static SqlSession sqlsession = null;
   
   // 싱글톤
   // mybatis와 다른 점 각 메소드마다 객체생성 할 필요없이 미리 만듬 
   private synchronized static SqlSession getSqlSession() {       
      if(sqlsession == null) {
         sqlsession = DBService.getFactory().openSession(false); // 수동 커밋이므로 커밋 필요한 메소드에서 따로 처리해줘야됌
      }
      return sqlsession;
   }
   
   // 메소드
   // 전체 데이터 개수 가져오기
   public static int getTotalRecord() {
      return getSqlSession().selectOne("total_record");
   }
   // 1. 전체 검색(index.jsp)
   // select * from bbs_t;
   public static List<BVO> getList(Map<String, Integer> map){
      return getSqlSession().selectList("list_bbs" , map);
   }
   // 2. 게시글 저장(insert.jsp)
   // insert into bbs_t values(작성자, 제목, 비밀번호, 첨부파일, 내용)
   public static int getInsert(BVO vo) {
      int result = getSqlSession().insert("insert_bbs", vo);
      if(result >0) {
         getSqlSession().commit();
      }
      return result;
   }
   // 3. 게시글 상세페이지(view.jsp)
   public static BVO getBBS(int b_idx) {
      return getSqlSession().selectOne("select_bbs", b_idx);
   }
   //4. 게시글 삭제
   public static int getRemove(int b_idx) {
	      int result = getSqlSession().delete("remove_bbs", b_idx);
	      if(result >0) {
	         getSqlSession().commit();
	      }
	      return result;
	   }
   //5. 게시글 수정
   public static int getupdate(BVO bvo) {
	      int result = getSqlSession().update("update_bbs", bvo);
	      if(result >0) {
	         getSqlSession().commit();
	      }
	      return result;
	   }
   //6.조회수 증가
   public static int getUpdateHit(BVO bvo) {
	      return getSqlSession().update("UpdateHit",bvo);
	   }
   //7.댓글 작성
   public static int getInsertComment(CVO vo) {
	      int result = getSqlSession().insert("insertComment_t", vo);
	      if(result >0) {
	         getSqlSession().commit();
	      }
	      return result;
	   }
   //8.댓글 목록
   public static List<CVO> getCommentList(int b_idx){
		return getSqlSession().selectList("getCommentList",b_idx);
	}
   //9.댓글 삭제
   public static int removeComment(int c_idx) {
	      int result = getSqlSession().delete("deleteComment_t", c_idx);
	      if(result >0) {
	         getSqlSession().commit();
	      }
	      return result;
	   }
}

'JSP > BBS' 카테고리의 다른 글

bbs.xml  (0) 2023.06.09
DBService  (0) 2023.06.09
Paging  (0) 2023.06.09
CVO  (0) 2023.06.09
BVO  (0) 2023.06.09