Tag Archives: PK

MyBatis insert 문 사용시 PK 획득하기 (useGeneratedKeys)

By | 9월 25, 2021

mybatis query xml <insert id="insertBook" useGeneratedKeys="true" keyProperty="bookId"> INSERT /* insertBook */ INTO book ( book_title ) VALUES ( #{bookTitle} ) </insert> 쿼리 이후 result 객체가 아닌 parameter 객체에서 bookId 를 참조하면 PK 획득. 이 테이블의 PK는 book_id 이지만 auto increment 이기 때문에 쿼리에는 기재되지 않았음. 대신 keyProperty 에 프로퍼티명이 명시되어 있음 mybatis config에 mapUnderscoreToCamelCase 가… Read More »