별칭을 #{별칭명}에 쓰면 됨
<insert id="insertUser">
<selectKey resultType="hashmap" keyProperty="maxDeptCode,maxPosCode,maxAuthCode" order="BEFORE">
SELECT
(SELECT MAX(DETAIL_CODE) FROM tb WHERE CMMN_CODE = 'mem_dept_code') AS maxDeptCode,
(SELECT MAX(DETAIL_CODE) FROM tb WHERE CMMN_CODE = 'mem_pos_code') AS maxPosCode,
(SELECT MAX(DETAIL_CODE) FROM tb WHERE CMMN_CODE = 'mem_auth_code') AS maxAuthCode
FROM DUAL
</selectKey>
INSERT INTO member
(
mem_id
, mem_dept_code
, mem_pos_code
, mem_auth_code
)
VALUES
(
#{memId}
<choose>
<when test="memDeptCode == 0">
, #{maxDeptCode}
</when>
<otherwise>
, #{memDeptCode}
</otherwise>
</choose>
<choose>
<when test="memPosCode == 0">
, #{maxPosCode}
</when>
<otherwise>
, #{memPosCode}
</otherwise>
</choose>
<choose>
<when test="memAuthCode == 0">
, #{maxAuthCode}
</when>
<otherwise>
, #{memAuthCode}
</otherwise>
</choose>
)
</insert>
처음에는 selectKey를 여러번 넣었으나 그건 안되는거같아서 쿼리를 하나로 조합해서 하니 되었다.