사용할 예제 : 특정 게시글(1)과 그 게시글 댓글(N)의 관계
데이터베이스 구성
drop table if exists board_tbl; create table board_tbl( bno int auto_increment primary key, title varchar(300) not null, content text not null, writer varchar(50) not null, regDate timestamp default current_timestamp, updateDate timestamp default current_timestamp ); insert into board_tbl(title,content, writer) values ('게시물 제목입니다.','내용 테스트1.','테스터1'); insert into board_tbl(title,content, writer) values ('게시물 제목입니다.2','내용 테스트2','테스터2'); insert into board_tbl(title,content, writer) values ('게시물 제목입니다.3','내용 테스트3','테스터3'); insert into board_tbl(title,content, writer) values ('게시물 제목입니다.4','내용 테스트4','테스터4'); select * from board_tbl;
create table reply_tbl( rno int primary key auto_increment, bno int not null, reply varchar(1000), replyer varchar(50), regDate timestamp default current_timestamp, updateDate timestamp default current_timestamp ); alter table reply_tbl add constraint fk_reply_board foreign key(bno) references board_tbl(bno); insert into reply_tbl(bno, reply, replyer) values('1','1번 게시물 첫 번째 댓글 내용입니다.','댓글작성자'); insert into reply_tbl(bno, reply, replyer) values('1','1번 게시물 두 번째 댓글 내용입니다.','댓글작성자'); insert into reply_tbl(bno, reply, replyer) values('1','1번 게시물 세 번째 댓글 내용입니다.','댓글작성자'); alter table board_tbl add column replyCnt int null default 0; update board_tbl set replyCnt = (select count(rno) from reply_tbl where board_tbl.bno = reply_tbl.bno); select * from reply_tbl;
모델 객체 : Board, ReplyVO
매퍼 작성
XML 작성
SpringMVC 자바스트립트, CSS 파일 적용하기 (0) | 2019.11.09 |
---|---|
Spring MVC 이미지 파일 불러오기 (0) | 2019.11.09 |
[4][Srping][Mybatis] 게시판 delete 사용 예제 (0) | 2019.11.07 |
[3][Srping][Mybatis] 게시판 updete 사용 예제 (0) | 2019.11.06 |
[2][Spring][MyBatis] 게시판 insert 사용 예제 (0) | 2019.11.06 |
댓글 영역