gorm 操作

当 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"
posted @ 2023-05-30 14:26  bhxuwei  阅读(48)  评论(0编辑  收藏  举报