从端点提取查询参数并附加到SQL查询

时间:2018-02-14 02:47:10

标签: mule

我有这样的端点 api.com/users?id=id1,id2,id3,id4,id5 ... id500

  1. 我需要从端点提取查询参数,即id1,id2 等......
  2. 然后我需要将参数附加到像这样的

    这样的SQL语句中

    选择column1,column2     来自my_table     其中column3喜欢' id1%&#39 ;;     或者列3喜欢' id2%'     或者列3喜欢' id4%' ..

  3. 关于如何实现这一目标的任何想法? 我对Mulesoft很新。

    #[message.inboundProperties.'http.query.params'.size()] gives me the number of values in the parameters
    
    #[message.inboundProperties.'http.query.params'.id] perhaps would give me an collection or arrayList ?
    

    我想循环遍历arrayList的每个项目以及类似的字符串 其中column3喜欢arrayList [0] +'%'

    但我对如何实现这一点毫无头绪并将其附加到SQL Query中,我将其发送到db。

2 个答案:

答案 0 :(得分:0)

您可以将查询参数设置为application / json,并以Json格式传递单个值,其中包含可在您的API中轻松提取的字段和值。

答案 1 :(得分:0)

1.获取查询字符串和setpayload的值。

<set-payload value="id1,id2,id3,id4,id5" doc:name="Set Sample Payload"/>

2.Create StringBuffer

  <expression-component doc:name="Expression"><![CDATA[StringBuffer sb = new 
    StringBuffer();
    flowVars.stBuffer=sb;
    ]]></expression-component>

3.拆分有效载荷

 <expression-transformer expression="#[message.payload.split(&quot;,&quot;)]" 
    doc:name="Split String"/>

4.通过在字符串缓冲区中附加值

,在for循环中构造sql
<foreach collection="#[payload]" doc:name="For Each">
           Construct sql here using string buffer
   </foreach>

参考:Splitting a comma-separated string and saving to database without DataWeave in Mule

相关问题