2016년 2월 23일 화요일

네이버의 카페(http://cafe.naver.com/gugucoding) 로 이전합니다.


안녕하세요.

구멍가게 코딩단의 집필 담당 쿠키입니다.

구멍가게 코딩단의 '코드로 배우는 스프링 웹 프로젝트'가 예상 밖(?)의 호응을 얻고 있어, 참으로 감사한 마음입니다.

많은 분들이 질문과 답변이 너무 지연 되는 경우가 많아서 불편하다고 말씀하셔서, 조심스럽게 네이버의 카페를 만들어서 운영하기로 결정하였습니다.


http://cafe.naver.com/gugucoding




그동안 빠르게 응대해 드리지 못해서 죄송합니다. 

앞으로 카페에 글을 올리시면 메일로 확인 가능하므로, 지금보다는 훨씬 빠른 답변이 가능할 것이라고 생각합니다. 

많은 이용 부탁드립니다. 

2016년 1월 6일 수요일

오라클버전 P502 테이블 변경


alter table tbl_board add (replycnt NUMBER(10,0) default 0);


P503

resources/mappers/boardMapper.xml의 일부


<select id="listCri"  resultType="org.zerock.domain.BoardVO">
 <![CDATA[
select
  bno, title, content, writer, viewcnt, regdate, replycnt
from
  (
  select
    /*+INDEX_DESC(tbl_board, pk_board)*/
    rownum rn, bno, title, content, writer, viewcnt, regdate
  from tbl_board
  where rownum <= #{page} * #{perPageNum}
  and bno > 0
  )
where rn > (#{page} -1) * #{perPageNum}
 ]]>
</select>

오라클버전 P418에 필요한 댓글의 페이징 처리 쿼리


<select id="listPage" resultType="ReplyVO">
<![CDATA[
 select
   rno, bno, replytext, replyer, regdate, updatedate
 from
   (
   select /*+INDEX_DESC(tbl_reply pk_reply))*/
     rownum rn, rno, bno, replytext, replyer, regdate, updatedate
   from tbl_reply
   where bno = #{bno}
   and rno > 0
   and rownum <= #{cri.page} * #{cri.perPageNum}
   )
where rn > ( #{cri.page} -1) * #{cri.perPageNum}
]]>
</select>

오라클버전 P373 resources/mappers/replyMapper.xml의 일부

<select id="list" resultType="ReplyVO">
select
*
from
tbl_reply
where bno =
#{bno}
order by rno desc
</select>

<insert id="create">
insert into tbl_reply (rno, bno, replytext, replyer)
values (seq_reply.nextval, #{bno},#{replytext},#{replyer})
</insert>

<update id="update">
update tbl_reply set replytext = #{replytext},
updatedate = sysdate
where rno = #{rno}
</update>

<delete id="delete">
delete from tbl_reply where rno =#{rno}
</delete>

오라클버전 P370 tbl_reply 테이블의 생성 스크립트



create table tbl_reply (
 rno number,
 bno number not null,
 replytext varchar2(2000) not null,
 replyer varchar2(50) not null,
 regdate date default sysdate,
 updatedate date default sysdate);

 --PK
 alter table tbl_reply add constraint pk_reply
 primary key (rno);

 --FK
 alter table tbl_reply add constraint fk_board_reply
 foreign key (bno) references tbl_board(bno);

 --sequence
 create sequence seq_reply;

오라클버전 P327 ~ P330 resources/mappers 밑의 boardMapper.xml의 일부




<sql id="search">
 <if test="searchType != null" >
   <if test="searchType == 't'.toString()">
     and title like '%'|| #{keyword}||'%'
   </if>
   <if test="searchType == 'c'.toString()">
     and content like '%'|| #{keyword}||'%'
   </if>
   <if test="searchType == 'w'.toString()">
     and writer like '%'|| #{keyword}||'%'
   </if>    
   <if test="searchType == 'tc'.toString()">
     and ( title like '%'|| #{keyword}||'%' OR content like '%'|| #{keyword}||'%')
   </if>      
   <if test="searchType == 'cw'.toString()">
     and ( content like '%'|| #{keyword}||'%' OR writer like '%'|| #{keyword}||'%')
   </if>      
   <if test="searchType == 'tcw'.toString()">
     and (   title like '%'|| #{keyword}||'%'
           OR
             content like '%'|| #{keyword}||'%'
           OR
             writer like '%'|| #{keyword}||'%')
   </if>            
 </if>
</sql>

<select id="listSearch"  resultType="org.zerock.domain.BoardVO">
 <![CDATA[
select
  bno, title, content, writer, viewcnt, regdate
from
  (
  select
    /*+INDEX_DESC(tbl_board, pk_board)*/
    rownum rn, bno, title, content, writer, viewcnt, regdate
  from tbl_board
  where 1=1
]]>
  <include refid="search"></include>
<![CDATA[
  and rownum <= #{page} * #{perPageNum}
  and bno > 0
  )
where rn > (#{page} -1) * #{perPageNum}
 ]]>
</select>

<select id="listSearchCount"  resultType="int">
 <![CDATA[
select
  count(bno)
from
  tbl_board
where 1=1
]]>
  <include refid="search"></include>
<![CDATA[
and bno > 0
 ]]>
</select>

오라클버전 P258 쿼리

select
*
from
  (
  select
  /*+INDEX_DESC(tbl_board pk_board) */
  rownum rn, bno, title, content, writer, regdate, viewcnt
  from tbl_board
  where bno > 0
  and rownum <= 40 )
where rn > 20;