當 where 字典的值為陣列時 gorm 會自動轉換為條件IN查詢
where := map[string]interface{}{}
where["id"] = [1,2,3]
where["name"] = "zhangsan"
type userList struct {
Id int "gorm:'id'"
Name string "gorm:'name'"
}
Table.Debug().where(where).find(&user).Error
// 生成的sql語句 select * form user where id in (1,2,3)and name = "zhangsan"
本作品採用《CC 協議》,轉載必須註明作者和本文連結