gorm - 查询为 或 为 null 的数据

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)