Programming/Spring

[iBatis/MyBatis] insert return key

깐니 2020. 10. 28. 22:55

 

<insert id="insertData" parameterType="DataClass" useGeneratedKeys="true"   

  keyProperty="id">



     /* query */



   <selectKey keyProperty="id" resultClass="int">

        SELECT LAST_INSERT_ID()

   </selectKey>

</insert>

 

int id = commonDB.insert(NAMESPACE + "insertData", dataClss);

 

id 값을 리턴 받는 곳 : DAO 클래스에서 insert문을 호출하는 구문

 

 

Ref.
https://marobiana.tistory.com/23