개발(~국비)/Servlet_JSP

NoticeService 클래스 구현 (71~76강 내용 정리,SQL 구문 포함)

까만밀가루 2022. 6. 8. 06:49

set linesize 300; --sql 구문에서 라인 정리 

 

NoticeService.class // 페이지 구현시 이용되는 전체 method

 

#.getNoticeList : 요청한 페이지 구현 method
select rownum, notice.* from notice order by regdate desc;
--rownum 후에 regdate 순으로 정렬

 

select rownum, n.* from (select * from notice order by regdate desc) n
where rownum between 1 and 5;
--정렬 된 상태의 결과물을 미리 만든 것에 rownum , 단 1부터 시작할 때만 정렬 가능

 


select * from(
   select rownum num, n.* from 
  (select * from notice order by regdate desc) n
)
where num between 6 and 10;
--만들어진 rownum의 번호를 num으로 한 후 페이징 할 수 있게 한다.

n:select * from notice order by regdate desc;,notice로부터 만들어진 새로운 쿼리

select * from(
   select row_number() over (order by regdate desc) num,
              notice.* from notice
)
where num between 6 and 10;

 

▶인자가 많은 method를 중심으로 오버로드 진행

▶검색 분류(field) , 검색 단어(query)

  •   field : title, writer_id
  •   query : '%A%' -> A포함, '%%' -> 제목 전부 포함 

 

#.getNoticeCount : 게시글 목록을 가져와 페이징 되지 않은 목록의 개수를 알아내는 method

 

 


return :  notice

 

order by regdate desc;

regdate  등록일 내림 차순 6/3 → 6/2 (점점 과거로)

 

--getPrevNotice
select id from (select * from notice order by regdate desc)
   where regdate < (select regdate from notice where id=3)
   and rownum=1

 

 

--getNextNotice
select * from notice
where id = (
   select id from notice 
   where regdate > (select regdate from notice where id=3)
   and rownum = 1
);

select id from notice where regdate > ( select regdate from notice where id=3 )
and rownum =1;
--바로 뒷 순서의 id만 얻기 위한 sql 명령어

 

--내가 한 getNextNotice   
select id from (select * from notice order by regdate asc)
   where regdate > (select regdate from notice where id=3)
   and rownum=1   

 

 

#.getNotice : 게시글 구현 method

while (x) → if

 

#.getNextNotice : 다음 게시글 구현 method

 

#.getPrevNotice:이전 게시글 목록 method