😎 Today I Learned

[TIL] 22.03.07

soozkim 2022. 3. 7. 23:38
Today I Learned

Board 추가

  • notice와 qna 겹치는 부분 board로 통일
  • BoardDAO, BoardDTO, BoardService 생성
  • Notice, Qna는 Board를 extends, implements 해서 사용
  • JSP 부분도 board로 통일

 

QnA - 답글, 댓글 

  • ref, step, depth 사용
  • ref : 원본글과 답글들을 그룹으로 묶는 역할
  • step : 그룹 내에서 순서를 결정하는 역할
  • depth : 들여쓰기 횟수

 - 원본글 작성
1) ref    : 자기 자신의 글번호가 ref 값이 됨
2) step   : 0
3) depth  : 0

 

 - 답글(댓글) 작성
1) ref    : 부모글의 ref를 자기의 ref값이 됨
2) step
   a. 테이블에서 ref가 부모의 ref와 같고 step이 부모의 step보다 큰것들(초과)을 각자의 step에 + 1 값으로 업데이트
   b. 부모글의 step에 +1 한 값을 자기의 step값이 됨
3) depth  : 부모글의 depth + 1 을 자기의 depth 값이 됨

 

Board 소스 코드

더보기

- BoardDTO

package com.spring.s1.board;

public class BoardDTO {
	private Long num;
	private String title;
	private String contents;
	private String writer;
	private String regDate;
	private Integer hit;
	
	public Long getNum() {
		return num;
	}
	public void setNum(Long num) {
		this.num = num;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContents() {
		return contents;
	}
	public void setContents(String contents) {
		this.contents = contents;
	}
	public String getWriter() {
		return writer;
	}
	public void setWriter(String writer) {
		this.writer = writer;
	}
	public String getRegDate() {
		return regDate;
	}
	public void setRegDate(String regDate) {
		this.regDate = regDate;
	}
	public Integer getHit() {
		return hit;
	}
	public void setHit(Integer hit) {
		this.hit = hit;
	}
	
	
}

 

- BoardDAO Interface

package com.spring.s1.board;

import java.util.List;

import com.spring.s1.util.Pager;

public interface BoardDAO {

	//detail
	public BoardDTO detail(BoardDTO boardDTO) throws Exception;
	
	//list
	public List<BoardDTO> list(Pager pager) throws Exception;
	
	//add
	public int add(BoardDTO boardDTO) throws Exception;

	//update
	public int update(BoardDTO boardDTO) throws Exception;
	
	//delete
	public int delete(BoardDTO boardDTO) throws Exception;
	
	//total
	public Long total(Pager pager) throws Exception;
}

- BoardService Interface

package com.spring.s1.board;

import java.util.List;

import com.spring.s1.util.Pager;

public interface BoardService {

	//list
	public List<BoardDTO> list(Pager pager) throws Exception;
	
	//detail
	public BoardDTO detail(BoardDTO boardDTO) throws Exception;
	
	//add
	public int add(BoardDTO boardDTO) throws Exception;
	
	//update
	public int update(BoardDTO boardDTO) throws Exception;
	
	//delete
	public int delete(BoardDTO boardDTO) throws Exception;
}
728x90