์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- Spring
- ์ปจํธ๋กค๋ฌ
- ๋ช ๋ น์ด
- like
- order by
- post๋ฐฉ์
- JS
- Ajax
- ๋ฐฑํฑ
- ํจ์
- ์ธ๋ผ์ธ๋ทฐ
- oracle
- ๋ฆฌ๋ ์ค
- select
- ๋์
- JSP
- DATE_FORMAT
- ๋์ปค
- ๋ฐฐ์ด
- MySQL
- SQL
- ํ ์ด๋ธ
- JavaScript
- ํ๋ก๊ทธ๋๋จธ์ค
- ๋ณ์
- Update
- ์๋ฐ์คํฌ๋ฆฝํธ
- ๋์ ํ ์ด๋ธ
- optionํ๊ทธ
- ์ฝํ
- Today
- Total
bom's happy life
[MyBatis] ๋์ ์ฟผ๋ฆฌ - if, choose, when ์ซ์, ๋ฌธ์์ด ๋น๊ต ๋ณธ๋ฌธ
[MyBatis] ๋์ ์ฟผ๋ฆฌ - if, choose, when ์ซ์, ๋ฌธ์์ด ๋น๊ต
bompeach 2023. 7. 17. 14:34๋ฌธ์์ด ๋น๊ต
* ์ด๋ค ๋น๊ต๋ฅผ ํ๋์ง null ์ฒดํฌ๋ฅผ ๋จผ์ ํ๋ค.
1. 'param.equals()'
<if test="name != null and 'name.equals(๋น๊ตํ ๋ฌธ์์ด)'">
column = #{name}
</if>
or
<if test='name != null and "name.equals(๋น๊ตํ ๋ฌธ์์ด)"'>
column = #{name}
</if>
2. ' ๋น๊ต๋์=="" ' ์ฑ๊ธ์ฟผํฐ๋ก ๊ฐ์ธ๊ณ ๋๋ธ์ฟผํฐ๋ก ๋น๊ต
<if test='name != null and name=="๋น๊ตํ ๋ฌธ์์ด"'>
column = #{name}
</if>
3. " ๋น๊ต๋์=='' " ๋๋ธ์ฟผํฐ๋ก ๊ฐ์ธ๊ณ ์ฑ๊ธ์ฟผํฐ๋ก ๋น๊ต
<if test="name != null and name=='๋น๊ตํ ๋ฌธ์์ด'">
column = #{name}
</if>
4. Null์ด ์๋๊ฑฐ๋ ๊ณต๋ฐฑ์ด ์๋์ง ์ฒดํฌ (" =='' ", ' =="" ' ๋๋ค ๊ฐ๋ฅํ๋ค)
<if test="name != null and name! = ''">
column = #{name}
</if>
๋ฌธ์(char)๋น๊ต
- ๋ฌธ์ ๋จ์ด์ ๊ธธ์ด๊ฐ ํ๊ฐ๋ก ์ง์ ํ ๊ฒฝ์ฐ
Map<Object, Object> params = new HashMap<Object, Object>();
params.put("type", "1");
1. ' ๋น๊ต๋์.equals("") '
<if test= 'type != null and type.equals("1")'> <!-- ์ฑ๊ณต -->
d_type = #{type}
</if>
2. " ๋น๊ต๋์.equals('') "--------- ๋ฌธ๋ฒ์๋ฌ๋ ์์ง๋ง ๋น๊ต ์๋จ
<if test= "type != null and type.equals('1')"> <!-- ๋น๊ต ์๋จ -->
d_type = #{type}
</if>
3. " ๋น๊ต๋์=='' " --------- ๋ฌธ๋ฒ์๋ฌ๋ ์์ง๋ง ๋น๊ต ์๋จ
<if test= "type != null and type == '1'"> <!-- ๋น๊ต ์๋จ -->
d_type = #{type}
</if>
4. ' ๋น๊ต๋์=="" '
<if test= 'type != null and type == "1"'> <!-- ์ฑ๊ณต -->
d_type = #{type}
</if>
5. Null์ด ์๋๊ฑฐ๋ ๊ณต๋ฐฑ์ด ์๋์ง ์ฒดํฌ (" =='' ", ' =="" ' ๋๋ค ๊ฐ๋ฅํ๋ค).
<if test= "type != null and type != ''">
d_type = #{type}
</if>
์ฃผ์ ์ฌํญ์ผ๋ก ์๋ฐ๋จ์์ ๋ฐ์ดํฐ ์ ์ ํ๋๋ถ๋ถ์์ ํ๊ฐ์ ์๋๋ฅผ ์ฑ๊ธ์ฟผ๋('')๋ก ๊ฐ์ธ๊ฒ ๋๋ฉด ์์ ๊ธฐ๋ฅ์ด ์ ์์ ์ผ๋ก ๋์ํ์ง ์๋๋ค. ex)params.put("type", '1');
์ซ์๋น๊ต
<if test= "idx != null and idx == 2">
d_idx = #{idx}
</if>
.
.
.
๋ธ๋ก๊ทธ ์ฐธ๊ณ ->
https://myhappyman.tistory.com/126
'Deveolpment Study๐๏ธ > Databases' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ด์ ์ ๊ณ์ฐํด์ ์์(RANK)๋ฅผ ๋งค๊ธฐ๊ณ ์ถ์๋? - ์ฟผ๋ฆฌ์ฑ๋ฅํฅ์์ํค๊ธฐ (0) | 2023.07.24 |
---|---|
[iBatis] id, parameterClass, resultClass (0) | 2023.07.24 |
[MySQL] ๊ธฐ๋ณธ๋ช ๋ น์ด (0) | 2023.07.17 |
[๋ฆฌ๋ ์ค] sql ํ์ผ ์ฎ๊ธฐ๊ณ -> sql ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ณต์ํ๊ธฐ์ํด ํ์ผ ์ฎ๊ธฐ๋ ๊ณผ์ (0) | 2023.07.17 |
[๋ฆฌ๋ ์ค] root๊ถํ ๋ก๊ทธ์ธ, mysql ์ ๊ทผ ๋ช ๋ น์ด (0) | 2023.07.17 |