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 更改为你的主键属性名即可。

posted @ 2017-01-12 09:29  邮储の桶  阅读(20412)  评论(0编辑  收藏  举报