mysql 批量插入id自增_mybatis获取批量插入的主键自增id

一、写一个实体类

public classUserInfo {private longuserId;privateString userAccount;privateString userPassword;privateString userName;private intuserStatus;privateString userCreateDatetime;privateString userRegisterIp;publicString getUserName() {returnuserName;

}public voidsetUserName(String userName) {this.userName =userName;

}public longgetUserId() {returnuserId;

}public void setUserId(longuserId) {this.userId =userId;

}publicString getUserAccount() {returnuserAccount;

}public voidsetUserAccount(String userAccount) {this.userAccount =userAccount;

}publicString getUserPassword() {returnuserPassword;

}public voidsetUserPassword(String userPassword) {this.userPassword =userPassword;

}public intgetUserStatus() {returnuserStatus;

}public void setUserStatus(intuserStatus) {this.userStatus =userStatus;

}publicString getUserCreateDatetime() {returnuserCreateDatetime;

}public voidsetUserCreateDatetime(String userCreateDatetime) {this.userCreateDatetime =userCreateDatetime;

}publicString getUserRegisterIp() {returnuserRegisterIp;

}public voidsetUserRegisterIp(String userRegisterIp) {this.userRegisterIp =userRegisterIp;

}

}

二、插入的mybatis insert语句

insert into system_user(

user_account,

user_password,user_name,

user_status,

user_create_datetime,

user_register_ip

)values

(

#{item.userAccount},

#{item.userPassword},

#{item.userName},

#{item.userStatus},

#{item.userCreateDatetime},

#{item.userRegisterIp}

)

三、dao接口

int batchInsert(List data);

然后再遍历data list里面的UserInfo实例,发现属性userId已经赋值为自增的id的值

第二种方法,单参数是map的时候。参数不是一个实体。

insert into system_oper_log

(

user_account,

operlog_url,

operlog_status,

operlog_ip,

operlog_exception,

operlog_type,

operlog_before,

operlog_after

)values(

#{user_account},

#{operlog_url},

#{operlog_status},

#{operlog_ip},

#{operlog_exception},

#{operlog_type},

#{operlog_before},

#{operlog_after}

)

然后再返回的map参数里面,返现多了一个键,叫做operlog_id

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值