码迷,mamicode.com
首页 > 其他好文 > 详细

【转】mybatis 获取自增id

时间:2016-05-22 00:34:13      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

转自:http://www.cnblogs.com/rhythmK/p/4047142.html

1、环境:

mybatis : 3.2.3

spring-mybatis:  1.2.1

mysql:5.5.29

实体:

技术分享
public class sys_user {
    private int userid;

    private String username;

   

    public int getUserid() {
        return userid;
    }

    public void setUserid(Integer userid) {
        this.userid = userid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    
技术分享

 

insert 节点配置:

技术分享
  <insert id="insert" parameterType="com.mamaguwen.entity.sys_user"   useGeneratedKeys="true" keyProperty="userid">
      
<!--    <selectKey keyProperty="userid" resultType="int" order="BEFORE">
         SELECT LAST_INSERT_ID()  as  userid
     </selectKey> -->
    insert into sys_user ( UserName)
    values (#{username})

  </insert>
技术分享

keyProperty:对应为实体字段值

调用代码:

sys_UserDao.insert(model);
System.out.println("getUserid:"+ model.getUserid());

   

 

【转】mybatis 获取自增id

标签:

原文地址:http://www.cnblogs.com/20000ding/p/5515958.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!