mybatis 插入返回自增後的id
阿新 • • 發佈:2018-12-07
//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