Programming/Java

[ MyBatis ] ๋™์ ํƒœ๊ทธ if ๋น„๊ต๋ฌธ + ์ˆซ์ž 0 ๋น„๊ต ์ด์Šˆ

seulye 2022. 8. 18. 14:37

 

์ฐธ๊ณ  : 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('')">

์ด๋ ‡๊ฒŒ ๋ณ€๊ฒฝํ•ด์ฃผ๋ฉด ์ž˜ ๋œ๋‹ค!