코배웹_페이징Sql

Web Development assistant·2021년 8월 1일
0

# cobeweb

목록 보기
3/6

sql, select id="getPagingWithList" include

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="org.zerock.mapper.BoardMapper">
	<sql id="criteria">
		<trim prefix="(" suffix=") and " prefixOverrides="or">
			<foreach collection="typeArr" item="type">
				<trim prefix="or">
					<choose>
						<when test="type == 'T'.toString()">
							title like '%' ||#{keyword}||'%'
						</when>
						<when test="type == 'C'.toString()">
							content like '%' ||#{keyword}||'%'
						</when>
						<when test="type == 'W'.toString()">
							writer like '%' ||#{keyword}||'%'
						</when>
					</choose>
				</trim>
			</foreach>
		</trim>
	</sql>

	<select id="getTotalCount" resultType="int">
		select count(*) from
		tbl_board where bno>0
	</select>

	<select id="getList" resultType="org.zerock.domain.BoardVO">
   		<![CDATA[
       		select * from tbl_board where  bno>0
   		]]>
	</select>

	<select id="getListWithPaging"
		resultType="org.zerock.domain.BoardVO">
	<![CDATA[
		select * from (
			select /*+ index_desc (tbl_board pk_board)*/ 
				bno, rownum rn,  title, content, writer, regdate, updatedate 
			from 
				tbl_board 
			where
	]]>
		<include refid="criteria"/>
	<![CDATA[
		rownum <=#{pageNum} * #{amount}
		)
	where rn>(#{pageNum}-1) *#{amount}
	]]>
	</select>

	<!-- <![CDATA[ select * from ( select /*+ index_desc (tbl_board pk_board)*/ 
		bno, rownum rn, title, content, writer, regdate, updatedate from tbl_board 
		where 0< bno and 0 < rownum and rownum <= (#{pageNum}*#{amount}) )where (#{pageNum}-1)*#{amount} 
		< rn ]]> </select> -->

	<insert id="insert">
		insert into tbl_board(bno, title, content, writer)
		values (seq_board.nextval, #{title}, #{content}, #{writer})
	</insert>

	<insert id="insertSelectKey">
		<selectKey order="BEFORE" keyProperty="bno"
			resultType="long">
			select seq_board.nextval from dual
		</selectKey>
		insert into tbl_board(bno, title, content, writer)
		values (#{bno}, #{title}, #{content}, #{writer})
	</insert>

	<select id="read" resultType="org.zerock.domain.BoardVO">
		select * from tbl_board where bno =
		#{bno}
	</select>

	<delete id="delete">
		delete from tbl_board where bno =#{bno}
	</delete>

	<update id="update">
		update tbl_board
		set
		title = #{title}
		,content = #{content}
		,writer = #{writer}
		,updatedate = sysdate
		where bno = #{bno}
	</update>
</mapper>

0개의 댓글