一、写一个实体类
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