zoukankan      html  css  js  c++  java
  • 【转】mybatis 获取自增id

    转自: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());

       

  • 相关阅读:
    C++ 类的本质 札记
    eclipse makefile
    boost 简介
    telecom 产品分析js
    javascript 得到页面参数
    ajax 接口统一模式
    备份
    jquery 元素插入详解
    使用WebClient制作一下简单的采集器
    数据库锁机制
  • 原文地址:https://www.cnblogs.com/20000ding/p/5515958.html
Copyright © 2011-2022 走看看