selectKey
Mybatis는 DB에서 특정값을 가져와서 쓸 수 있도록 selectKey 기능을 제공한다.
속성
- keyProperty : selectKey 구문의 결과가 셋팅될 대상 프로퍼티
- keyColumn : 리턴되는 결과셋의 컬럼명은 프로퍼티 명과 일치된다.
- resultType
- order : BEFORE || AFTER를 셋팅할 수 있다.
- BEFORE : 키를 조회한 후, 그 값을 keyProperty에 세팅한 후 구문을 실행한다.
- AFTER : 구문을 실행한 후, selectKey 구문을 실행한다.
- statementType : STATEMENT || PREPARED || CALLABLE 중 하나를 선택할 수 있다.
- statementType : STATEMENT || PREPARED || CALLABLE 중 하나를 선택할 수 있다.
<insert id="" parameterType="">
<selectKey order="BEFORE" keyProperty="userId" resultType="int">
...Query...
</selectKey>
...Query...
</insert>
<insert id="" parameterType="">
...Query...
<selectKey order="AFTER" keyProperty="userId" resultType="int">
...Query...
</selectKey>
</insert>
'회사 > Spring' 카테고리의 다른 글
[Spring] @RequestBody / @RequestParam 비교 (0) | 2025.04.11 |
---|---|
[SPRING] LOGIN INTERCEPTOR (0) | 2025.03.18 |
[Spring] @Transactional과 try-catch (0) | 2024.09.02 |
[Spring] ObjectMapper (0) | 2024.03.27 |