๐คselectKey : SELECT ๋ช ๋ น์ ์คํ๊ฒฐ๊ณผ๋ก ๊ฐ์ ์ ๊ณต๋ฐ์ insert ์๋ฆฌ๋จผํธ์ parameterType ์์ฑ๊ฐ์ผ๋ก ์ค์ ๋ ๊ฐ์ฒด์ ํ๋๊ฐ์ผ๋ก ์ ์ฅํ๊ธฐ ์ํ ์๋ฆฌ๋จผํธ
=> insert ์๋ฆฌ๋จผํธ์ ์ข ์๋ ์๋ฆฌ๋จผํธ
=> ์๋ ์ฆ๊ฐ๊ฐ ๋๋ ๋์๊ฐ์ SELECT ๋ช
๋ น์ผ๋ก ๊ฒ์ํ์ฌ ๊ฐ์ฒด ํ๋์ ์ ์ฅํด INSERT ๋ช
๋ น์์ ์ฌ์ฉํ๊ธฐ ์ํ ์์ฑ
โช๏ธ resultType ์์ฑ : SELECT ๋ช
๋ น์ผ๋ก ๊ฒ์๋ ๊ฒฐ๊ณผ๊ฐ์ ์ ๊ณต๋ฐ๊ธฐ ์ํ Java ์๋ฃํ์ ์์ฑ๊ฐ์ผ๋ก ์ค์
=> J ava ์๋ฃํ ๋์ typeAlias ์๋ฆฌ๋จผํธ๋ก ์ค์ ํ ๋ณ์นญ(AliasName) ์ฌ์ฉ ๊ฐ๋ฅ
โช๏ธ keyProperty ์์ฑ : insert ์๋ฆฌ๋จผํธ์ parameterType ์์ฑ๊ฐ์ผ๋ก ์ค์ ๋ ํด๋์ค์ ํ๋๋ช
์ ์์ฑ๊ฐ์ผ๋ก ์ค์ - ์ ๋ฌ๋ฐ ์ ๊ฐ์ฒด์ ํ๋๊ฐ์ผ๋ก ์ ์ฅ
โช๏ธ order ์์ฑ : [BEFORE] ๋๋ [AFTER] ์ค ํ๋๋ฅผ ์์ฑ๊ฐ์ผ๋ก ์ค์
<insert id="insertComment2" parameterType="MyComment1">
<selectKey resultType="int" keyProperty="commentNo" order="BEFORE">
select mycomment_seq.nextval from dual
</selectKey>
insert into mycomment values(#{commentNo}, #{commentId}, #{commentContent}, sysdate)
</insert>