MyBatis+MySQL map 返回插入的主键ID

  • Post author:
  • Post category:mysql


MyBatis+MySQL map返回插入的主键ID

1.service


userDao.insert(map);

int i = Integer.parseInt(map.get("id").toString());

2.Mapper.xml

    <insert id="insert"  parameterType="java.util.Map" useGeneratedKeys="true" keyProperty="id" keyColumn="id">  
        <selectKey resultType="int" order="AFTER" keyProperty="id">   
            SELECT LAST_INSERT_ID() as id  
        </selectKey>  
            insert into user_info(name,age,create_time,address)   
        values (#{name,jdbcType=VARCHAR},  
        #{age,jdbcType=TINYINT},  
        #{create_time,jdbcType=DATE},  
        #{address,jdbcType=VARCHAR})  
    </insert>  



版权声明:本文为solrChina原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。