【golang】gorm 使用map实现in 条件查询用法

当 where 字典的值为数组时 gorm 会自动转换为条件 IN 查询

go 复制代码
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"

相关推荐
油腻中年李大鹅3 小时前
使用scheduler-plugins实现自定义调度器
kubernetes·go
DemonAvenger3 小时前
减少内存分配:Go中值类型与指针类型的选择
性能优化·架构·go
Piper蛋窝7 小时前
我所理解的 Go 的 `panic` / `defer` / `recover` 异常处理机制
后端·go
叹一曲当时只道是寻常9 小时前
AI书签管理工具开发全记录(十三):TUI基本框架搭建
ui·go
岁忧10 小时前
(nice!!!)(LeetCode每日一题)2434. 使用机器人打印字典序最小的字符串(贪心+栈)
java·c++·算法·leetcode·职场和发展·go
喵个咪13 小时前
MQTT 协议下的Last Will and Testament(LWT,遗嘱消息)
后端·go
DemonAvenger1 天前
Go并发编程:内存同步与竞态处理
性能优化·架构·go
叹一曲当时只道是寻常1 天前
xmind转换为markdown
go·xmind
程序员爱钓鱼1 天前
Go 并发编程基础:通道(Channel)的使用
后端·google·go
fashia1 天前
Java转Go日记(六十):gin其他常用知识
开发语言·后端·golang·go·gin