gorm - 查询为 "" 或 为 null 的数据

一. model

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

 

二. 查询

u := query.User

cond := 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)

 

posted @ 2025-12-28 18:20  _Q  阅读(2)  评论(0)    收藏  举报