ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

gorm - 查询为 或 为 null 的数据

2026/8/8 17:13:01 拓冰建站 浏览量
gorm - 查询为  或 为 null 的数据

一. model

type User struct {Name                       `gorm:"column:name;type:varchar(255);`Title                         `gorm:"column:title;type:varchar(255);`
}

 

二. 查询

u := query.Usercond := u.WithContext(ctx).Clauses()
cond.Where(u.Title.Eq("")).Or(u.Title.IsNull())u.WithContext(ctx).
Where(u.Name.Like("%" + name + "%")).
Where(cond).
FindByPage(page.Offset, page.Limit)