Filter方法和Exclude方法内部都是使用SetCond方法来连接查询字符串的。当然这里我们也可以直接使用SetCond来自己连接查询字符串,然后使用同样的方法去查询数据。Filter方法和Exclude方法原型如下。
Filter(string, ...interface{}) QuerySeter
Exclude(string, ...interface{}) QuerySeter
而在beego框架中,这两个方法的实现如下:
// add condition expression_r to QuerySeter.
func (o querySet) Filter(expr string, args ...interface{})
QuerySeter {
if o.cond == nil {
o.cond = NewCondition()
}
o.cond = o.cond.And(expr, args...)
return &o
}
// add NOT condition to querySeter.
func (o querySet) Exclude(expr string, args ...interface{})
QuerySeter {
&nbs