xml파일에 조건문을 쓰고싶은 경우 어떻게 쓰는지 정리해둔다.
조건문을 쓰면 xml에 쿼리 작성 개수를 줄일 수 있을 것 같기에 자주 사용할 것 같은 느낌이든다.
mapper에서 if 조건문 예제
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<if test="nick != null">
nick = #{nick},
</if>
<if test="checkThom.equals("nick")">
nick = #{nick},
</if>
<if test="checkThom.equals("nick") and checkNoma.equal("noma")>
nick = #{nick},
</if>
<choose>
<when test="checkThom.equals("nick")"> nick = #{nick}, </when>
<when test="numb >= 8 "> numb = #{numb}, </when>
<otherwise> else query </otherwise>
</choose>
<foreach collection="gubun" item="item" separator="OR" open="(" close=")">
foreach query
</foreach>
|
cs |
'IT기술 > spring' 카테고리의 다른 글
DAO / VO / DTO란? (0) | 2021.09.18 |
---|---|
[spring] Driver net.sf.log4jdbc.sql.jdbcapi.DriverSpy claims to not accept jdbcUrl, jdbc:log4jdbc:oracle:thin:@localhost:1521:XE 오류해결 (2) | 2021.09.18 |
[IssueCase] java.sql.SQLException: Access denied for user ‘ID’@’xxx.xxx’ (using password: YES (0) | 2021.08.31 |
MyBatis, mybatis 는 무엇인가? (0) | 2021.01.24 |
tomcat 내부구조 알아보기 (0) | 2020.01.21 |