mybatis插入完數據後返回主鍵id

因牽涉到多張表進行插入數據,後面插入需要前面插入的主鍵id,用於構建主外鍵關係,因此插入完數據後需要id回傳

將useGeneratedKeys屬性設置爲true    
keyProperty設置成主鍵id名

<insert id="insertTmParentSystem" parameterType="com.tmao.entity.tmall.TableTmParentSystem" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO tm_system (sys_name, sys_eng_name, p_cid)
        VALUES
          (#{sys_name},#{sys_eng_name},#{p_cid})
    </insert>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章