mybatis中插入記錄後返回該記錄的主鍵id

<insert id="insert" parameterType="com.mjs.mojisishop.entity.ItemCat" useGeneratedKeys="true" keyProperty="id">
        insert into mj_item_cat (typeName, superType, typeSort,
        showStatus, created, updated
        )
        values (#{typename,jdbcType=VARCHAR}, #{supertype,jdbcType=BIGINT}, #{typesort,jdbcType=INTEGER},
        #{showstatus,jdbcType=INTEGER}, #{created,jdbcType=TIMESTAMP}, #{updated,jdbcType=TIMESTAMP}
        )
    </insert>

加上 useGeneratedKeys=“true” keyProperty=“id” 這兩個屬性

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