想得到的是这种sql语句
[INSERT INTO `user` (`name`, `email`, `age`, `is_active`) VALUES (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?)] str是一个切片数组
现在代码得到的sql语句都是单条插入 求大神来解决
var info models.Info
for num, strsclice := range str {
if num == 0 {
continue
}
phone := strsclice[0]
name := strsclice[1]
sex := strsclice[2]
address := strsclice[3]
qq := strsclice[4]
weixin := strsclice[5]
age := strsclice[6]
//批量插入数据
books := []models.Info{
{Phone: phone, Name: name, Sex: sex, Address: address, Qq: qq, Weixin: weixin, Age: age},
}
if err := info.InsertMulti(len(books), books); err != nil {
beego.Error(err)
this.Data["json"] = map[string]interface{}{"message": "导入数据库失败!!!"}
this.ServeJSON()
} else {
beego.Warning("Excel有效数据行数:[", len(str)-1, "] Excel列数[", sheet.MaxCol, "]")
this.Data["json"] = map[string]interface{}{"message": "导入数据库成功!!!"}
this.ServeJSON()
}
}
}
有疑问加站长微信联系(非本文作者)