MyBatis+MySQL 返回插入的主键ID
<insert id="insertSelective" useGeneratedKeys="true" keyProperty="id" parameterType="com.model.Channel" > insert into channel <trim prefix="(" suffix=")" suffixOverrides="," > <if test="id != null" > id, </if> <if test="shopId != null" > shop_id, </if> ......
学习:
http://www.cnblogs.com/gengaixue/p/5276596.html
或者:
<insert id="insertSelective" parameterType="com.tuling.model.Channel" > <selectKey keyProperty="id" resultType="int"> select LAST_INSERT_ID() </selectKey> insert into channel <trim prefix="(" suffix=")" suffixOverrides="," > <if test="id != null" > id, </if> <if test="shopId != null" > shop_id, </if> ......