1. 程式人生 > >mybatis 主鍵UUID生成策略

mybatis 主鍵UUID生成策略

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

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

<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>