Mule - 数据库中参数的对象
Mule - Object to parameters in Database
我有这个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,我用class转换为对象 其中包含:
@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;
}
}
最后,我调用了我的数据库。我如何分配,例如属性关于table名字来自class 到数据库元素中的参数?
例如,
<db:in-param name="table_name" type="VARCHAR" value="PROPERTY OF CLASS"/>
使用 MEL(Mule 表达式语言)和标准 Java 方法调用。由于数据是您的有效载荷,因此使用#[payload.table_name] MEL 将自动对该字段使用 getter。
我有这个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,我用class转换为对象 其中包含:
@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;
}
}
最后,我调用了我的数据库。我如何分配,例如属性关于table名字来自class 到数据库元素中的参数?
例如,
<db:in-param name="table_name" type="VARCHAR" value="PROPERTY OF CLASS"/>
使用 MEL(Mule 表达式语言)和标准 Java 方法调用。由于数据是您的有效载荷,因此使用#[payload.table_name] MEL 将自动对该字段使用 getter。