[ MyBatis ] ๋์ ํ๊ทธ if ๋น๊ต๋ฌธ + ์ซ์ 0 ๋น๊ต ์ด์
์ฐธ๊ณ : https://hellogk.tistory.com/100
mybatis์ ibatis๋ณ ๋์ ํ๊ทธ ๋น๊ต๋ฌธ ์์๋ณด๋๋ก ํ์
์ฐ์ mybatis์ ibatis์์๋ ๋์ ํ๊ทธ๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ์ง์์ ํฉ๋๋ค. ์ฆ, ํ๋ก์์ ๋ก ์ง์ฌ์ ธ ์๋ ๋ก์ง์ ๋์ ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ ์ฟผ๋ฆฌ๋ก ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. ์ฅ์ ์ด ์์์๋ ์์ง๋ง ์์นซ ์๋ชป ์ฌ์ฉ
hellogk.tistory.com
์ ํ์ฌ์์๋ iBatis๋ฅผ ์ผ์ด์ ๊ทธ๋ฐ์ง ๊ฝค ๋ค๋ฅธ ์ ์ด ์์๋ค.
ํท๊ฐ๋ ค์ ๊ณ์ ์ฐพ์๋ณด๋ค๊ฐ, ๋ฑ ์ ๋ฆฌ๋ฅผ ํด๋์ผ๋ฉด ์ข์ ๊ฒ ๊ฐ์์ ํฌ์คํ ํ๋ค.
1. null ๋น๊ต
<if test="stringProperty == null">
์กฐ๊ฑด๋ฌธ
</if>
<if test="stringProperty != null">
์กฐ๊ฑด๋ฌธ
</if>
2. ๊ณต๋ฐฑ ๋น๊ต
<if test="stringProperty == ''">
์กฐ๊ฑด๋ฌธ
</if>
<if test="stringProperty != ''">
์กฐ๊ฑด๋ฌธ
</if>
null ๋น๊ต์ ๊ฐ์ด ==, !=๋ฅผ ํตํด ๋น๊ตํ๋ฉด ๋๋ค.
3. ๋ฌธ์์ด ๋น๊ต
<if test="stringProperty.equals('a')">
์กฐ๊ฑด๋ฌธ
</if>
<if test="!stringProperty.equals('a')">
์กฐ๊ฑด๋ฌธ
</if>
<if test="channelType != null and channelType != ''">
์ซ์๋ก 0์ด ๋์ด์ค๊ฒ ๋๋ฉด ''์ ๊ฐ๋ค๊ณ ์ธ์์ ํ๋ค๊ณ ํ๋ค.
<if test="channelType != null and !channelType.equals('')">
์ด๋ ๊ฒ ๋ณ๊ฒฝํด์ฃผ๋ฉด ์ ๋๋ค!