[java] 카테고리 구현

Yuni·2023년 3월 23일
0

Java

목록 보기
5/14
post-thumbnail
  1. 부서

  1. 부서 + 모든 키워드

많은 블로그들을 찾다가 좋은 글을 발견했다

https://kimvampa.tistory.com/181

정말 꼼꼼하게 작성하셔서 오류없이 한번에 페이징과 검색기능을 만들었다
근데 내가 필요한건 한 부서를 적어둔 테이블 안에서 부서를 가져와서 검색하는 법..!
저 분의 글을 참고하되 mybatis와 select부분은 다시 만들었다!
따라 하실 분들은 저 링크를 타고가서 하신 다음에 요부분만 보고 하시면 될듯 싶다!

list.jsp
<select name="type" class="btn btn-outline-select dropdown-toggle">
	<option value="ABCDE" <c:out value="${pageMaker.cri.type eq 'ABCDE'?'selected':'' }"/>>전체</option>
	<option value="A" <c:out value="${pageMaker.cri.type eq 'A'?'selected':'' }"/>>기술연구소</option>
	<option value="B" <c:out value="${pageMaker.cri.type eq 'B'?'selected':'' }"/>>영업부</option>
	<option value="C" <c:out value="${pageMaker.cri.type eq 'C'?'selected':'' }"/>>기술지원</option>
	<option value="D" <c:out value="${pageMaker.cri.type eq 'D'?'selected':'' }"/>>경영관리</option>
	<option value="E" <c:out value="${pageMaker.cri.type eq 'E'?'selected':'' }"/>>관리자</option>
</select>
<input type="text" name="keyword" class="enterkey form-control" value="${pageMaker.cri.keyword }" aria-describedby="button-addon2">
<button class="serch btn btn-outline-bt-se" type="button" >검색</button>

Mapper.xml

	<!-- 게시물 목록(페이징) -->
	<select id="getListPaging" resultMap="UserResult">
		select * from tbl_user u
		LEFT JOIN tbl_part p
		ON p.part_id = u.user_part
		WHERE u.user_authority > 0

		<if test="keyword == '' and type != ''">
			<trim prefix="AND">
				<if test="type != ''">
					<if test="type == 'A'.toString()">
						p.part_id = 0
					</if>
					<if test="type == 'B'.toString()">
						p.part_id = 1
					</if>
					<if test="type == 'C'.toString()">
						p.part_id = 2
					</if>
					<if test="type == 'D'.toString()">
						p.part_id = 3
					</if>
					<if test="type == 'E'.toString()">
						p.part_id = 4
					</if>
				</if>
			</trim>
		</if>

		<if test="keyword != '' and keyword != null and type != '' and type != null">
			AND (u.user_id like concat('%',#{keyword},'%') OR
			u.user_phone like concat('%',#{keyword},'%') OR
			u.user_name like concat('%',#{keyword},'%') OR
			u.user_email like concat('%',#{keyword},'%' ) OR
			u.user_signdate like concat('%',#{keyword},'%')) AND
			u.user_authority > 0
			<trim prefix="AND">
				<if test="type == 'A'.toString()">
					p.part_id = 0
				</if>
				<if test="type == 'B'.toString()">
					p.part_id = 1
				</if>
				<if test="type == 'C'.toString()">
					p.part_id = 2
				</if>
				<if test="type == 'D'.toString()">
					p.part_id = 3
				</if>
				<if test="type == 'E'.toString()">
					p.part_id = 4
				</if>
			</trim>
		</if>
		
		order by u.user_signdate desc
		limit #{skip},#{amount}
	</select> 
	
	<!-- 게시물 총 개수 -->
	<select id="getTotal" resultType="int">
		select count(*) from tbl_user u
		LEFT JOIN tbl_part p
		ON p.part_id = u.user_part
		WHERE u.user_authority > 0

		<if test="keyword == '' and type != ''">
			<trim prefix="AND">
				<if test="type != ''">
					<if test="type == 'A'.toString()">
						p.part_id = 0
					</if>
					<if test="type == 'B'.toString()">
						p.part_id = 1
					</if>
					<if test="type == 'C'.toString()">
						p.part_id = 2
					</if>
					<if test="type == 'D'.toString()">
						p.part_id = 3
					</if>
					<if test="type == 'E'.toString()">
						p.part_id = 4
					</if>
				</if>
			</trim>
		</if>

		<if test="keyword != '' and keyword != null and type != '' and type != null">
			AND (u.user_id like concat('%',#{keyword},'%') OR
			u.user_phone like concat('%',#{keyword},'%') OR
			u.user_name like concat('%',#{keyword},'%') OR
			u.user_email like concat('%',#{keyword},'%' ) OR
			u.user_signdate like concat('%',#{keyword},'%')) AND
			u.user_authority > 0
			<trim prefix="AND">
				<if test="type == 'A'.toString()">
					p.part_id = 0
				</if>
				<if test="type == 'B'.toString()">
					p.part_id = 1
				</if>
				<if test="type == 'C'.toString()">
					p.part_id = 2
				</if>
				<if test="type == 'D'.toString()">
					p.part_id = 3
				</if>
				<if test="type == 'E'.toString()">
					p.part_id = 4
				</if>
			</trim>
		</if>
	</select> 
profile
backend developers

0개의 댓글