IT/Java Spring

ch10.SpringMVC 종합 14. 검색

Millennials 2020. 6. 29. 10:51

1)BoardMapper

<?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="kr.spring.board.dao.BoardMapper">  
	<select id="selectRowCount" parameterType="map" resultType="integer">
		SELECT COUNT(*)	FROM spboard b JOIN spmember m ON b.mem_num=m.mem_num
		<where>
			<if test="keyword != '' and keyfield == 'title'">
				b.title LIKE '%' || #{keyword} || '%'
			</if>
			<if test="keyword != '' and keyfield == 'id'">
				m.id LIKE '%' || #{keyword} || '%'
			</if>
			<if test="keyword != '' and keyfield == 'content'">
				b.content LIKE '%' || #{keyword} || '%'
			</if>
		</where>
	</select>
	<select id="selectList" parameterType="map" resultType="boardVO">
		SELECT * FROM (SELECT a.*, rownum rnum FROM 
			(SELECT * FROM spboard b JOIN spmember m ON b.mem_num=m.mem_num
			<where>
				<if test="keyword != '' and keyfield == 'title'">
					b.title LIKE '%' || #{keyword} || '%'
				</if>
				<if test="keyword != '' and keyfield == 'id'">
					m.id LIKE '%' || #{keyword} || '%'
				</if>
				<if test="keyword != '' and keyfield == 'content'">
					b.content LIKE '%' || #{keyword} || '%'
				</if>
			</where>
			 ORDER BY b.num DESC) a
		)<![CDATA[ WHERE rnum >= #{start} AND rnum <= #{end} ]]>
	</select>
</mapper>

2)실행 및 오류체크

반응형