gorm 使用map实现in 条件查询用法
当 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 协议》,转载必须注明作者和本文链接
推荐文章: