赞
踩
我之前以为在xml中设置了useGeneratedKeys="true" keyProperty="id"
就可以了
其实不然,这只是返回自增主键id。
如果用的是uuid字符串我就们就需要在下面加入一行代码
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
select LAST_INSERT_ID()
</selectKey>
xml示例代码
<insert id="insertSelective" parameterType="com.demo.GoodsSpecPO" useGeneratedKeys="true" keyProperty="id"> <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long"> select LAST_INSERT_ID() </selectKey> insert into table_name <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> id, </if> <if test="specIndex != null"> spec_index, </if> <if test="name != null"> `name`, </if> <if test="type != null"> `type`, </if> <if test="categoryId != null"> category_id, </if> <if test="creator != null"> creator, </if> <if test="creatorId != null"> creator_id, </if> <if test="updator != null"> updator, </if> create_time, update_time, deleted, <if test="version != null"> version, </if> </trim>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。