Chanho_Park

[mybatis] spring xml 에서 다양한 작성법 본문

Spring/mybatis

[mybatis] spring xml 에서 다양한 작성법

Chanho_Park 2022. 11. 14. 23:01
728x90

검색을 사용할 때 '%keyword%' 이렇게 작성하는 법

<select id="getTotalCount" resultType="int">
		select count(*) from client 
		<if test="whatColumn=='code'">where code like '%' ||  #{keyword} || '%'</if>
		<if test="whatColumn=='category'">where category like '%' ||  #{keyword} || '%'</if>
</select>

 

String[] 이나 Arraylist 등을 보내서

반복문 사용법

Collection : 형태를 적어준다. 배열이나 Array 는 array

item : 바꿀 변수를 적어준다.

open : 반복문을 시작하기전에 작성할 것

close : 반복문을 끝나고 나서 작성할 것

separator : 반복 배열 사이에 넣어줄 문자

 

<delete id="selectDelete">
		delete client where no in 
		<foreach collection="array" item="arr" open='(' close=")" separator=",">
		#{arr}
		</foreach>
	</delete>

이렇게 작성하게 되면

delete client where no in ( arr[0] , arr[1] , arr[2] ) 

이렇게 작성된다.

728x90