2015-11-23 60 views
0

我有這個mule flow騾子 - 對象參數數據庫

<?xml version="1.0" encoding="UTF-8"?> 

<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd 
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd 
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd"> 

    <spring:beans> 

     <spring:bean id="propertyConfigurer" 
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
      <spring:property name="locations"> 
       <spring:list> 
        <spring:value>configSQL.properties</spring:value> 
       </spring:list> 
      </spring:property> 
     </spring:bean> 

    </spring:beans> 

    <db:generic-config name="BBDD_USER" doc:name="Generic Database Configuration" driverClassName="net.sourceforge.jtds.jdbc.Driver" 
    url="${sql.url}/${sql.database};user=${sql.username};password=${sql.password}"/> 

    <flow name="sincro-sql" doc:name="sincro-sql"> 

     <http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8042" doc:name="HTTP"/> 

     <logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="JSON"/> 

     <json:json-to-object-transformer doc:name="JSON to Object" returnClass="json.database.object.Data"/> 

     <db:stored-procedure config-ref="BBDD_USER" doc:name="Data" source="json.database.object.Data" streaming="true"> 
      <db:parameterized-query><![CDATA[{ CALL dbo.ExecSQL(:table_name, :field_name) }]]></db:parameterized-query> 
      <db:in-param name="field_name" type="VARCHAR" value="field_test"/> 
      <db:in-param name="table_name" type="VARCHAR" value="table_test"/> 
     </db:stored-procedure> 

    </flow> 
</mule> 

收到一個JSON變換與類,它包含反對

@JsonAutoDetect  
public class Data{ 

     private String table_name; 
     private String field_name; 

     public void setTableName(String table_name) { 
      this.table_name= table_name; 
     } 

     public String getTableName() { 
      return table_name; 
     } 

     public void setFieldName(String field_name) { 
      this.field_name= field_name; 
     } 

     public String getFieldName() { 
      return field_name; 
     } 
    } 

最後,我打電話給我的數據庫。我怎樣才能分配,例如財產關於從類到參數數據庫元素表名

例如,

<db:in-param name="table_name" type="VARCHAR" value="PROPERTY OF CLASS"/> 

回答

1

使用MEL(騾表達語言特點)和標準的Java方法調用。由於數據是您的有效載荷,請使用#[payload.table_name] MEL將自動爲該字段使用getter。

+0

謝謝!如果它是一個數組,我應該使用什麼? – user1911

+0

好,如果你想在數組中的特定項目,您可以通過索引訪問它:#[有效載荷[0]。表名] –

+0

對不起,我發佈了一個新的答案解釋更多的細節:http://stackoverflow.com/問題/ 33892365/mule-object-from-array-to-parameter-in-database謝謝 – user1911