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