Loading

MyBatis+MySQL 返回插入的主键ID

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>
......

 

posted @ 2017-03-23 14:56  stono  阅读(428)  评论(0编辑  收藏  举报