2017-03-03 18 views
0

我在設計ords api並遇到以下問題。ords url參數不起作用

我想設計下列API:

/ords/schema_name/customers/?name=somename 

可能返回的項目,其中列customer_name等於輸入參數name,如果設置的URL。

的ORDS服務定義爲:

BEGIN 
    ORDS.DEFINE_SERVICE(
     p_module_name => 'customers' , 
     p_base_path => '/customers/', 
     p_pattern  => ':id?', 
     p_source  => 'select * from customers where customer_id = nvl(:id,customer_id) and UPPER(customer_name) = nvl(UPPER(:name),UPPER(customer_name))' 
    ); 

    COMMIT; 
END; 

不過,我從請求/ords/schema_name/customers/?name=somename得到了resonse是爲請求/ords/schema_name/customers/相同。它從數據庫返回所有客戶。

我也試過發送請求到/ords/schema_name/customers?name=somename。不是運氣也。

我想知道爲什麼url上的參數不起作用,以及如何解決它。

+0

我會嘗試/ ords/schema/customers?key = somekey。這裏有類似的例子http://www.thatjeffsmith.com/archive/2017/03/a-tale-of-two-styles-of-uris-and-parameters-words/ – thatjeffsmith

+0

@thatjeffsmith我也試過發送請求到'/ ords/schema_name/customers /?key = somekey'。不是運氣也。 – fluency03

+0

@thatjeffsmith但我也看到很多線路上的例子都在做'.../customers /?key = somekey'。 – fluency03

回答

0

有幾種方法可以查詢ORDS。

  1. 列表:http://<server>:<port>/ords/scott/emp
  2. 度日PK:http://<server>:<port>/ords/scott/emp/7788
  3. 排序:
    http://<server>:<port>/ords/scott/emp?q={"$orderby":{"ENAME":"ASC"}} http://<server>:<port>/ords/scott/emp?q={"$orderby":"SAL":"DESC","ENAME":"ASC"}}
  4. 過濾:
    http://<server>:<port>/ords/scott/emp?q={"SAL":5000} 
    http://<server>:<port>/ords/scott/emp?q={"SAL":{"$eq":5000}} 
    

注:如果您使用的是ORDS高級模式安裝即。使用單獨的Tomcat服務器來運行ORDS服務器,那麼你必須知道tomcat的版本。最新版本的tomcat [apache-tomcat-8.5.11,apache-tomcat-8.0.39]不支持查詢參數,但您必須傳遞編碼格式,而不是普通格式。

爲了編碼,你可以使用encodeURIComponent方法() JavaScript函數:

encodeURIComponent('{"field_name": "<value>"}') 

同樣,它支持普通的查詢參數apache-tomcat-8.0.30