下面是一个查询users列表的函数:
func ListUser(username string, offset, limit int) ([]*UserModel, uint64, error) { if limit == 0 { limit = constvar.DefaultLimit } users := make([]*UserModel, 0) var count uint64 where := fmt.Sprintf("username like '%%%s%%'", username) //这个语句的作用是什么? if err := DB.Self.Model(&UserModel{}).Where(where).Count(&count).Error; err != nil { return users, count, err } if err := DB.Self.Where(where).Offset(offset).Limit(limit).Order("id desc").Find(&users).Error; err != nil { return users, count, err } return users, count, nil}
问题:
上面代码中where := fmt.Sprintf("username like '%%%s%%'", username)
这个语句的作用是什么?
跃然一笑
相关分类