标签:
下面总结了两种方式,一种是使用oracle的sys_guid函数自动生成,另一种是使用sequence,
方法一:
<insert id="insert" useGeneratedKeys="false" keyProperty="storeId" parameterType="zttc.itat.user.po.TStore" >
<selectKey resultType="String" keyProperty="storeId" order="BEFORE">
select sys_guid() from dual
</selectKey>
insert into T_STORE (STORE_ID, STORE_NAME, STORE_PRICE,CREATE_DATE,END_DATE
)
values ( #{storeId,jdbcType=VARCHAR}, #{storeName,jdbcType=VARCHAR}, #{storePrice,jdbcType=DECIMAL},
#{createDate,jdbcType=VARCHAR},#{endDate,jdbcType=VARCHAR}
)
</insert>
方法二:
<insert id="insert" parameterType="zttc.itat.user.po.TStore" >
insert into T_STORE (STORE_ID, STORE_NAME, STORE_PRICE,CREATE_DATE,END_DATE
)
values (my_sequence.nextval, #{storeName,jdbcType=VARCHAR}, #{storePrice,jdbcType=DECIMAL},
#{createDate,jdbcType=VARCHAR},#{endDate,jdbcType=VARCHAR}
)
</insert>
<insert id="insert" useGeneratedKeys="false" keyProperty="storeId" parameterType="zttc.itat.user.po.TStore" >
<selectKey resultType="String" keyProperty="storeId" order="BEFORE">
select my_sequence.nextval as storeId from dual
</selectKey>
insert into T_STORE (STORE_ID, STORE_NAME, STORE_PRICE,CREATE_DATE,END_DATE
)
values ( #{storeId,jdbcType=VARCHAR}, #{storeName,jdbcType=VARCHAR}, #{storePrice,jdbcType=DECIMAL},
#{createDate,jdbcType=VARCHAR},#{endDate,jdbcType=VARCHAR}
)
</insert>
标签:
原文地址:http://www.cnblogs.com/ycblus/p/5500527.html