我在使用「自定義變形金剛」的時候有過這樣的想法。所以我用這個java變壓器。
的邏輯看起來是這樣的:
public class QueryBuilder extends AbstractMessageTransformer {
@Override
public Object transformMessage(MuleMessage message, String outputEncoding)
throws TransformerException {
System.out.println("Query Params : "
+ message.getInboundProperty("http.query.params").getClass()
.getName());
Map<?, ?> map = message.getInboundProperty("http.query.params");
System.out.println("Map keys : " + map.keySet());
String where = "";
for (Map.Entry<?, ?> entry : map.entrySet()) {
System.out.println(entry.getKey() + "/" + entry.getValue());
where = where+" "+entry.getKey()+"="+"'"+entry.getValue()+"'"+" and";
}
String whereCondition = where.substring(0, where.lastIndexOf(" "));
System.out.println("Where condition is : "+ where.substring(0, where.lastIndexOf(" ")));
return whereCondition;
}}
現在這個返回它的有效載荷是字符串類型。
在數據庫連接器中,選擇查詢類型爲動態。 其中條件添加#[有效載荷]。
乾杯
使用動態查詢類型以這種方式添加WHERE條件是否安全? – mCeviker