mybatis生成UUID主鍵,且獲取當前新增的UUID主鍵
阿新 • • 發佈:2019-03-11
<insert id="insert" parameterType="User"> <selectKey keyProperty="userId" resultType="java.lang.String" order="BEFORE"> select uuid() </selectKey> INSERT INTO ll_user (user_id, name, pwd, user_tel, wx_name,wx_headimg,role_id, status, ad_id, address, logout_time,type, is_create_goods, community_id, community_name,union_id, open_id_gzh, open_id_xcx) VALUES (#{userId}, #{name}, #{pwd}, #{userTel}, #{wxName},#{wxHeadImg}, #{roleId}, #{status}, #{adId}, #{address}, #{logoutTime},#{type},#{isCreateGoods}, #{communityId}, #{communityName}, #{unionId}, #{openIdGzh}, #{openIdXcx}) </insert>
keyProperty:selectKey子元素返回值將賦值到領域模型的哪個屬性中。
resultType:返回結果型別
order:BEFORE 標識在執行插入語句之前執行
在設定keyProperty="userId"時這段程式碼會在執行insert語句之前產生一條uuid並賦值到當前user物件中的userId中。
所以在新增成功後直接getUserId就可以獲取當