gin 框架 controller 层总会定义个结构体去接收请求参数,把结构体透传到 dao 层,dao 层自己根据 tag 去过滤,免去写一堆垃圾 if
type QueryFruits struct {
Fruit string `json:"fruit" filter:"column:fruit;operator:like"`
}
d.Model(&Fruit{}).Scopes(func (db *gorm.DB) *gorm.DB){
scope := xxxx()
return db.Where(scope)
}
type QueryFruits struct {
Fruit string `json:"fruit" filter:"column:fruit;operator:like"`
}
d.Model(&Fruit{}).Scopes(func (db *gorm.DB) *gorm.DB){
scope := xxxx()
return db.Where(scope)
}