在Params模型中我有一个 int 数组Cat_id
我提出一个要求:localhost:8080/products/?cat_id=1,2 我想展示这两个类别的多个产品。我如何解析地构建我的查询?我的功能:
func GetAllIproducts(q *models.Products, pagination *models.Params) (*[]models.Products, error) {
var prod []models.Products
offset := (pagination.Page - 1) * pagination.Limit
result := config.DB.Model(&models.Products{}).Where(q).Where("cat_id=?", pagination.Cat_id).Limit(pagination.Limit).Offset(offset).Find(&prod) //Problem is here
if result.Error != nil {
msg := result.Error
return nil, msg
}
return &prod, nil
}
当我使用时Debug,我得到了这个: SELECT * FROM "products" WHERE cat_id=(1,2) AND "products"."deleted_at" IS NULL
慕标5832272
相关分类