Skip to content

搜索操作符参考

VEF Framework 搜索标签支持的操作符完整参考。

比较操作符

操作符说明SQL示例
eq等于= valuesearch:"eq"
ne不等于<> valuesearch:"ne"
gt大于> valuesearch:"gt"
gte大于等于>= valuesearch:"gte"
lt小于< valuesearch:"lt"
lte小于等于<= valuesearch:"lte"

字符串操作符

操作符说明SQL示例
like模糊匹配LIKE '%value%'search:"like"
likeLeft左模糊LIKE '%value'search:"likeLeft"
likeRight右模糊LIKE 'value%'search:"likeRight"
notLike不匹配NOT LIKE '%value%'search:"notLike"

集合操作符

操作符说明SQL示例
in包含IN (values)search:"in"
notIn不包含NOT IN (values)search:"notIn"

范围操作符

操作符说明SQL示例
between范围内BETWEEN v1 AND v2search:"between"
notBetween范围外NOT BETWEEN v1 AND v2search:"notBetween"

空值操作符

操作符说明SQL示例
isNull为空IS NULLsearch:"isNull"
isNotNull不为空IS NOT NULLsearch:"isNotNull"

特殊操作符

操作符说明示例
-忽略字段search:"-"

附加标签

标签说明示例
column:"name"指定列名column:"user_name"
columns:"a,b,c"多列搜索columns:"username,email"
ignoreEmpty:"true"忽略空值ignoreEmpty:"true"
join:"Relation"关联表join:"Department"

完整示例

go
type OrderSearch struct {
    // Basic comparison
    Status      string   `search:"eq"`
    MinAmount   float64  `search:"gte" column:"amount"`
    MaxAmount   float64  `search:"lte" column:"amount"`
    
    // String matching
    OrderNo     string   `search:"like"`
    CustomerName string  `search:"like" column:"customer_name"`
    
    // Collection
    Statuses    []string `search:"in" column:"status"`
    ExcludeIds  []string `search:"notIn" column:"id"`
    
    // Date range
    CreatedFrom string   `search:"gte" column:"created_at"`
    CreatedTo   string   `search:"lte" column:"created_at"`
    
    // Null check
    HasRemark   bool     `search:"isNotNull" column:"remark"`
    
    // Multi-column search
    Keyword     string   `search:"like" columns:"order_no,customer_name,remark"`
    
    // Related table
    ProductName string   `search:"like" column:"Product.name" join:"Product"`
    
    // Ignored fields
    Page        int      `search:"-"`
    PageSize    int      `search:"-"`
    SortField   string   `search:"-"`
    SortOrder   string   `search:"-"`
}

类型映射

Go 类型推荐操作符
stringeq, like, in
int, int64eq, gt, gte, lt, lte, in, between
float64eq, gt, gte, lt, lte, between
booleq
*booleq (可选)
[]stringin, notIn
time.Timeeq, gt, gte, lt, lte, between

基于 Apache License 2.0 许可发布