条件筛选

This commit is contained in:
2023-06-19 02:21:25 +08:00
parent 240ffdcf78
commit 7349f5a1d6

View File

@@ -36,6 +36,21 @@ func ModelsGet(w http.ResponseWriter, r *http.Request) {
db.Where("name LIKE ?", "%"+name+"%")
}
// 按照 type 篩選
if model_type := r.URL.Query().Get("type"); model_type != "" {
db.Where("type = ?", model_type)
}
// 按照 status 篩選
if status := r.URL.Query().Get("status"); status != "" {
db.Where("status = ?", status)
}
// 按照 tag 篩選
if tag := r.URL.Query().Get("tag"); tag != "" {
db.Where("tags LIKE ?", "%"+tag+"%")
}
db.Offset((listview.Page - 1) * listview.PageSize).Limit(listview.PageSize).Find(&model_list)
for _, model := range model_list {
listview.List = append(listview.List, model)