[英]How to use the “find where” SailsJS blueprint route?
我想使用SailsJS“ Find Where ”藍圖路徑創建一個包含多個條件的復雜查詢。 但是,我無法成功使用equals比較器和條件。 我找不到關於如何實現Find Where路由的充分文檔,因此我完成了源代碼並提出了以下方案。
使用SailsJS Find Where Blueprint Route,如何實現:
以下方案將返回相應的響應:
http://localhost:1337/api/user?name=fred
http://localhost:1337/api/user?where={"name":{"startsWith":"fred"}}
http://localhost:1337/api/user?where={"name":{"endsWith":"fred"}}
http://localhost:1337/api/user?where={"name":{"contains":"fred"}}
http://localhost:1337/api/user?where={"name":{"like":"fred"}}
http://localhost:1337/api/user?where={"or":[{"name":{"startsWith":"fred"}}]}
http://localhost:1337/api/user?where={"or":[{"name":{"startsWith":"fred"}},{"path":{"endsWith":"fred"}}]}
以下方案返回空響應:
http://localhost:1337/api/user?where={"name":{"equals":"fred"}}
http://localhost:1337/api/user?where={"name":{"=":"fred"}}
http://localhost:1337/api/user?where={"name":{"equal":"fred"}}
http://localhost:1337/api/user?where={"and":[{"name":{"startsWith":"fred"}}]}
http://localhost:1337/api/user?where={"and":[{"name":{"startsWith":"fred"}},{"path":{"endsWith":"fred"}}]}
要使用“和”查詢,請使用&符號一起使用查詢字符串語法和鏈標准。 對於OR
或復雜運算符等更高級的查詢,最好編寫控制器操作。 如果您決定堅持使用藍圖,則可以使用編碼為JSON的大多數有效Waterline查詢。
對於簡單查詢,您使用查詢字符串方法。 以下將為姓名和學校構建“和”查詢。
http://localhost:1337/api/user?name=fred&school=foo
要將更高級的運算符鏈接在一起,以下應該可以工
http://localhost:1337/api/user?where={"name":{"startsWith":"fred"},"path":{"endsWith":"fred"}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.