* 게시판 소스

 

board_fc.zip


1. 보려는 page = 현재페이지
2. total 게시물 = DB
3. page 내 게시물 수 = utilities
4. pageGroup 내 page = utilites

◀ -> 이전 page group 유무
1 2 3 4 5 ->현재 page가 속한 page Group을 알아야 한다. 이를 바탕으로 시작 page와 끝 page를 알아낸다. 그후 시작~끝까지
                루프를 돌려 알아낸다. 
▶ -> 다음 page group의 유무(있으면 Link를 걸고, 없으면 Link를 걸면 안된다.)

* 위의 작업을 list.jsp에서 해야하는데 이 작업은 공통이기 때문에 계산을 bean(pagingDTO.java)에서 처리하고 list.jsp에서는 가져다 쓴다.  


* 아래 PagingDTO.java 안에 메소드를 채워라.

PagingDTO.java

board.zip


class :
package : board.dto
name : ListDTO

 

 

 

--------------------------목록 페이지 조회 - 페이징 처리된 -----------------------------

시작 : show_content.jsp : 글목록(페이징) 링크 클릭 시 command : list
Ctr : BoardListController.execute()
BoardService : getBoardListByPage(int page) : ListDTO
BoardDAO : selectBoardListByPage(int page) : ArrayList<BoardDTO>
                  selectTotalContent() : int - count함수 사용
응답 : list.jsp



 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 * 결과보기

Posted by 조은성
,

* list : 게시물
* page : 게시물 묶음
* pageGroup : page 묶음

 

* rownum - 조회된 레코드(row)의 number(순서 값)을 가지는 가상의 컬럼
                       - rownum은 조회하는 순간에 자동으로 생성이 된다.
                      - page 처리와 N-top 조회(제일 위에 있는 것)에 많이 사용된다.

ex :


 

 

* rownum을 가지고 한 페이지에 5개씩 자르기( rownum/ 5 )
1/5 = 0.2
2/5 = 0.4
3/5 = 0.6
4/5 = 0.8
5/5 = 1
 - 소수점을 올림하여 나누는 수 이하의 수는 1로 셋팅.(오라클에서 올림 ceil()을 지원)

* ceil을 사용하면 첫번째 페이지에 있는 값을 조회가 가능하나그 이후 rownum의 값은 조회가 안된다.(이를 해결하기 위해 서브 쿼리를 사용한다.

 - 첫번째 rownum 조회

 - 2번째 rownum부터는 조회가 안됨.

- rownum=2가 안되는 이유 : rownum은 where로 조건을 검사 한 후에 결정되기 때문에 rownum=1 이후의 값은 들어 갈 수 없다.
* 해결 :  where조건을 하기 전에 미리 rownum을 셋팅한다.(서브쿼리 사용)

 

 

- 이렇게 하면 처음 조건이 1이라 절대 2가 나올 수 없다. 조건이 만족하지 않기때문에 따라서 서브 쿼리를 사용해서 결과를 다시 조회한다.

- 이 후 다시 정렬을 해준다.

- 정렬을 위와 같이 먼저 해주면 정렬이 조건을 검사한 후에 일어나서 page의 정렬이 깨지게 되므로 정렬을 먼저 아래와 같이 해주고 나서 계산을 해줘야 한다.

- 그 후에 page가 2인 것만 뽑기 위해 다음과 같이 다시 서브 쿼리를 만들어 정리를 한다.

 




 

* 서브 쿼리 (쿼리 안에 쿼리 넣기)
select rownum, id, name from member where name like '%홍%' order by id asc;를 먼저 조회하고 where rownum=3을 조회하면 값이 나온다.

ex :
- 먼저 다음과 같이 테이블로 조회한 후에

- 그 결과를 바탕으로 다시 조회해 온다.





* 쿼리 실행 순서
( 1.from -> 2. where -> 3. group by -> 4. having -> 5. select컬럼 -> 6. order by )

select 컬럼
from table
where 조건
group by 그룹명
having 조건
order by 정렬기준

ex :
select rownum, id, name from member where name like '%홍%' order by id asc;


* group by

- 부서별로 salary가 제일 높은 것
select max(salary), 부서 from 테이블명 group by 부서

* having부서별로 salary를 정렬을 하고 다시 salay가 5000이상인 것 조회

select max(salary), 부서 from 테이블명 group by 부서 having  max(salary)>=5000

Posted by 조은성
,

1. 게시판을 만들기 위해 테이블을 먼저 생성한다.

create table board(
 no number,
 title varchar2(150) not null,
 writer varchar2(30) not null,
 content varchar2(4000) not null,
 writedate varchar2(14) not null,
 viewcount number not null,
 --답변과 관련된 속성
 refamily number not null,
 restep number not null,
 relevel number not null,
 constraint board_pk primary key(no)
)

2. 시퀀스(게시글번호)를 위해 시퀀스 번호를 생성한다.

select board_no_seq.nextval from dual;

3. 데이터 값을 담아둘 dto를 만든다.

board.dto

 

 

 

4. * utility 만들기
class
package : board.util
name : DBUtil
           Utilities

 

 

 

5. service만들기

 

 

 

6. controller 만들기

interface
package : board.controller
name : Controller

 

 

class : ControlerCommandMapping

 

 

 

servlet
package : board.controller
name : BoardFrontController : mapping - /boardController

 

 

 

* 위와 같이 하면 기본적으로 DB연동할 준비를 하고 패턴을사용하고 기본 함수를 완성해 둔 것임 

7. 새 글작성을 한다.

- ${initParam.context_root }를 사용하기 위해 web.xml에 아래와 같이 적어 넣는다.

 

 

- write_form.jsp를 만든다.

 

 

- boardController 전송을 누르면 연결 시킨다.

 

4. 실제로 WriteContentController()를 만든다.
controller -> BoardController -> WriteContentController

 

- 서비스를 통해 DB와 연결하여 값을 얻어오게 한다.

BusinessService -> BoardService.writeContent(BoardDTO)

 

 

- DB에서값을 얻어온다. dao 작성

DAO -> BoardDAO.selectBoardNo : 글번호 조회
            BoardDAO.insertContent(BoardDTO) - 새글, 답변글



- 화면을 만든다.
응답 -> show_content.jsp : 정상처리
           error.jsp : 오류 발생시

 

 

 

 

* BoardService와 BoardDAO는 싱글턴패턴으로 만들어라.

 

* lib에 javax.servlet.jsp.jstl-1.2.1.jar, javax.servlet.jsp.jstl-api-1.2.1.jar 넣기

 

* 결과

 

* 전체 글목록 조회(no paging)

시작 : show_content.jsp - 링크(command=list_all)
Ctr : BoardAllListController.execute()
BoardService : getBoardAllList() : ArrayList<BoardDTO>
BoardDAO : selectBoardAllList() : ArrayList<BoardDTO
                 - 정렬 : refamily 내림차순(desc)
응답 : list_all.jsp

 

시작 : show_content.jsp - 링크(command=list_all)

 

 

- Ctr : BoardAllListController.execute()

 

 

 

 

 

- service

 

- dao

 

- list_all.jsp

 

 

* 결과

 

 

- 제목으로 검색하기

 

 

 

 

 

 

 

 

 

 

 

 - 결과

 

 

-------------수정폼 조회하기------------

시작 : show_content.jsp에서 글수정 링크 클릭 command : modify_form
Ctr : ModifyFormController.execute();
BoardService : getContentByNOForForm(int no) : BoardDTO
BoardDAO : selectContentByNO(int no) : BoardDTO
응답 : modify_form.jsp

 

 

Ctr : ModifyFormController.execute();

 

 

 

 

 

BoardService : getContentByNOForForm(int no) : BoardDTO

 

 

 

 

 

* 결과보기

 

-------------글 수정 처리---------------

시작 : modify_form.jsp에서 수정버튼 클릭 command : modify_content
Ctr : ModifyContentController.execute();
BoardService : modifyContent(BoardDTO bdto) : void
BoardDAO : updateContent(BoardDTO bdto)
- 제목, 작성자, 내용, 일시

응답 : show_content.jsp

 

 

 

 

 

 

 

 

 

 

 

* 결과보기

 

 

 

 

시작 : show_content.jsp 삭제링크 클릭. cmd : delete_content
Ctr : DeleteContentController.execute()
BoardService : deleteContentByNO(int no) : void
BoardDTO : deleteContentByNO(int no)

응답 : list_all.jsp

 

 

 

 

 

 

 

 

 

 

 

 

 

 

* 결과보기

 

 

 

 

 

-------------------답변폼 조회----------------------

시작 : show_content.jsp 답변링크 클릭. command : reply_form
Ctr : ReplyFormController.execute()
BoardService : getContentByNOForForm(int no) : BoardDTO
BoardDAO : selectContentByNO(int no) : BoardDTO
응답 : reply_form.jsp

 

 

 

 

 

 

 

 

 

 

* 결과보기

 

 

 

---------------------------답변처리----------------- 

시작 : reply_form.jsp 답변버튼 클릭. command : reply_content
Ctr : ReplyContentController.execute()
BoardService : replyContent(BoardDTO)
BoardDAO : updateRestep(int refamily, int restep)
                  selectBoardNO()
                  insertContent()

응답 : show_content.jsp

 

 

 

 

 

 

 

 

 

 

 

* 결과보기

 

 

 

 

 

Posted by 조은성
,
Posted by 조은성
,

-------------------답변폼 조회----------------------

시작 : show_content.jsp 답변링크 클릭. command : reply_form
Ctr : ReplyFormController.execute()
BoardService : getContentByNOForForm(int no) : BoardDTO
BoardDAO : selectContentByNO(int no) : BoardDTO
응답 : reply_form.jsp


---------------------------답변처리----------------- 

시작 : reply_form.jsp 답변버튼 클릭. command : reply_content
Ctr : ReplyContentController.execute()
BoardService : replyContent(BoardDTO)
BoardDAO : updateRestep(int refamily, int restep)
                  selectBoardNO()
                  insertContent()

응답 : show_content.jsp

 

-------------------답변폼 조회----------------------

시작 : show_content.jsp 답변링크 클릭. command : reply_form
Ctr : ReplyFormController.execute()
BoardService : getContentByNOForForm(int no) : BoardDTO
BoardDAO : selectContentByNO(int no) : BoardDTO
응답 : reply_form.jsp

 

 

 

 

 

 

 

 

 

 

* 결과보기

 

 

 

---------------------------답변처리----------------- 

시작 : reply_form.jsp 답변버튼 클릭. command : reply_content
Ctr : ReplyContentController.execute()
BoardService : replyContent(BoardDTO)
BoardDAO : updateRestep(int refamily, int restep)
                  selectBoardNO()
                  insertContent()

응답 : show_content.jsp

 

 

 

 

 

 

 

 

 

 

 

* 결과보기

 

 

 

 

 

Posted by 조은성
,

시작 : show_content.jsp 삭제링크 클릭. cmd : delete_content
Ctr : DeleteContentController.execute()
BoardService : deleteContentByNO(int no) : void
BoardDTO : deleteContentByNO(int no)

응답 : list_all.jsp

 

 

 

 

 

 

 

 

 

 

 

 

 

 

* 결과보기

 

 

 

 

 


'프로그래밍 > JSP Programming' 카테고리의 다른 글

게시판 소스  (0) 2012.05.18
2012-5-18 답변폼 조회  (0) 2012.05.18
2012-5-17 게시판 글수정하기  (0) 2012.05.17
2012-5-17 게시판 글번호로 조회  (0) 2012.05.17
2012-5-17 전체 글목록 조회(no paging)  (0) 2012.05.17
Posted by 조은성
,

-------------수정폼 조회하기------------

시작 : show_content.jsp에서 글수정 링크 클릭 command : modify_form
Ctr : ModifyFormController.execute();
BoardService : getContentByNOForForm(int no) : BoardDTO
BoardDAO : selectContentByNO(int no) : BoardDTO
응답 : modify_form.jsp

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

-------------글 수정 처리---------------

시작 : modify_form.jsp에서 수정버튼 클릭 command : modify_content
Ctr : ModifyContentController.execute();
BoardService : modifyContent(BoardDTO bdto) : void
BoardDAO : updateContent(BoardDTO bdto)
- 제목, 작성자, 내용, 일시

응답 : show_content.jsp

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Posted by 조은성
,

---------------글번호로 조회--------------------------------

시작 : list_all.jsp(목록에서 글제목 클릭시) - command=get_content
Ctr : GetContentController.execute();
BoardService : getContentByNO(int no) : BoardDTO
BoardDAO : updateViewCount (int no)
                 selectContentByNO(int no) : BoardDTO
응답 : show_content.jsp


 


 

 

 

 

 

 

 

 

 

 * 결과보기

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Posted by 조은성
,

* 전체 글목록 조회(no paging)

시작 : show_content.jsp - 링크(command=list_all)
Ctr : BoardAllListController.execute()
BoardService : getBoardAllList() : ArrayList<BoardDTO>
BoardDAO : selectBoardAllList() : ArrayList<BoardDTO
                 - 정렬 : refamily 내림차순(desc)
응답 : list_all.jsp

* controller

 

 

 

 

 

* dto

 

 

 

* dao

 

 

* service

 

 

* util

 

 

 

* jsp

 

 

 


* 결과보기

 

 

 

Posted by 조은성
,

* controller

 

 

 

 

* DTO

 

 

 

* DAO

 

 

* service

 

 

* util

 

 

 

 

 

* 결과보기

 

 

Posted by 조은성
,