主键自增方式:采用主键自增 字段为int类型, 第二种为UUID策略自增
此文主要UUID形式自增
由于采用UUID形式,当insert时 主键的值无法获取,所以采用 <selectKey>标签, 此标签可以获取到UUID的value,
select replace(uuid(),'-','') AS id 以下为 语句A的结果传入到insert的主键里面,
<insert id="createMarketing" parameterType="BizMarketing" useGeneratedKeys="true" keyProperty="id"> <selectKey keyProperty="id" resultType="java.lang.String" order="BEFORE"> select replace(uuid(),'-','') AS id </selectKey> insert into tbl_marketing_activities <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null and id != ''">id,</if> <if test="owner != null and owner !=''">owner,</if> <if test="name != null and name !=''">name,</if> <if test="startDate != null and startDate !=''">startDate,</if> </trim> <trim prefix="values(" suffix=")" suffixOverrides=","> <if test="id != null and id != ''">#{id},</if> <if test="owner != null and owner !=''">#{owner},</if> <if test="name != null and name !=''">#{name},</if> <if test="startDate != null and startDate !=''">#{startDate},</if> </trim> </insert>