//serviceImpl int customerId = customerDao.insertDynamic(customer1); System.out.println("id===================="+customer1.getId());
useGeneratedKeys:开启获取主键
keyProperty:那个字段是主键
<insert id="insertDynamic" parameterType="com.wftdlx.carApi.entity.Customer" useGeneratedKeys="true" keyProperty="id">
insert into customer
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="activedate != null" >
activedate,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="activedate != null" >
#{activedate,jdbcType=VARCHAR},
</if>
</trim>
</insert>
输出:id====================195466