查询filter的使用
运算符列表
运算符 | 描述 | 对应C#运算符 |
eq | 等于 | == |
ne | 不等于 | != |
gt | 大于 | > |
ge | 大于等于 | >= |
lt | 小于 | < |
le | 小于等于 | <= |
and | 且 | && |
or | 或 | || |
() | 分组 | () |
实例
$filter 条件表达式
1、名字等于【eq】Candice的所有信息
$filter=Name eq 'Candice'
2、名字不等于【ne】Candice的所有信息
$filter=Name ne 'Candice'
3、年龄大于【gt】18的所有信息
$filter=Age gt 18
4、年龄大于等于【ge】18的所有信息
$filter=Age ge 18
5、年龄小于【lt】18的所有信息
$filter=Age lt 18
6、年龄小于等于【le】18的所有信息
$filter=Age le 18
7、名字等于Candice并且【and】年龄小于等于18的所有信息
$filter=Name eq 'Candice' and Age le 18
8、名字等于Candice或者【or】年龄小于等于18的所有信息
$filter=Name eq 'Candice' or Age le 18
9、名字等于Candice年龄年龄小于18 或者 名字等于Candy年龄大于18的所有信息 ()
$filter=(Name eq 'Candice' and Age lt 18) or (Name eq 'Candy' and Age gt 18)
特殊情况,如果入参中有日期字段,那么首先应当知道结构中的日期格式是下面三种的哪一种
EDM.Time | stores time between 00:00:00 to 23:59:59 |
EDM.DateTime | store values in the your DC server’s local time in format 2022-06-02T00:00:00 |
EDM.DateTimeOffset | store time values in UTC time zone in format 2022-06-02T00:00:00Z |
首先通过$metadata 去看下结构
![](https://img-blog.csdnimg.cn/img_convert/0cdad3dff399f789a27e75937f04426f.png)
本例子中格式是Edm.DateTime 所以格式应该如datetime‘2022-06-02T00:00:00′
/sap/opu/odata/SAP/ZMM_GET_MB51_SRV/Zmb51Set?$format=json&$filter=Budat eq datetime'2022-06-06T00:00:00'
![](https://img-blog.csdnimg.cn/img_convert/024d29e6920cca3306ab3b60c949be92.png)