mybatis 主鍵UUID生成策略


<insert id="insert" parameterType="com.lsfwpt.lawmis.po.SysUser">
        <selectKey keyProperty="userId//你的主鍵屬性名" resultType="String" order="BEFORE">
            select replace(uuid(),'-','') from dual //原樣照抄 </selectKey>
        insert into sys_user (user_id, user_name, login_name,
        user_pwd)
        values (#{userId,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR},
        #{loginName,jdbcType=VARCHAR},
        #{userPwd,jdbcType=VARCHAR})
    </insert>

在使用mybatis mapper.xml 進行接口實現的時候,使用UUID主鍵生成策略。

如上面代碼所示只需將 selectKey 標簽中的 keyProperty 更改為你的主鍵屬性名即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM