You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
513 B
22 lines
513 B
package mysql
|
|
|
|
import (
|
|
"main/models"
|
|
)
|
|
|
|
func ImportStudentInfoIntoSql(s []models.User) (err error) {
|
|
for _, user := range s {
|
|
user_id := user.User_id
|
|
user_name := user.User_name
|
|
user_gender := user.User_gender
|
|
user_score := user.User_score
|
|
|
|
// 插入数据到数据库,如果数据冲突则替换
|
|
_, err := db.Exec("REPLACE INTO user (user_id, user_name, user_gender, user_score) VALUES (?, ?, ?, ?)", user_id, user_name, user_gender, user_score)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return
|
|
}
|