3
版本:1.7.0 操作系统:win10
疑问:为什么要将原有? 按照参数个数替换成多个?呢 我自己已经拼接了多个问号,但是gf where又添加了;
代码如下:
where := " 1 = 1 "
var params []interface{}
if form.Params != nil {
if form.Params["username"] != "" {
where += " and t.username like ? "
params = append(params, "%"+form.Params["username"]+"%")
}
if form.Params["realName"] != "" {
where += " and t.real_name like ? "
params = append(params, "%"+form.Params["realName"]+"%")
}
if gconv.Int(form.Params["userType"]) > 0 {
where += " and t.user_type = ? "
params = append(params, gconv.Int(form.Params["userType"]))
}
if gconv.Int(form.Params["departId"]) > 0 {
where += " and t.depart_id = ? "
params = append(params, gconv.Int(form.Params["departId"]))
}
}
num, err := model.dbModel("t").Where(where, params).Count()