问题
I am fetching the data from database with SQL, I need pass a variable to the where clause, however, I find that the string concatenation doesn't work, even the official example
* def batchnum = "112344552"
* def getBatchIDSQL = '#("select id from sr_sendreceive where batchnum = " + batchnum)'
* print getBatchIDSQL
* def sendReceiveBatchid = db.readValue('#(getBatchIDSQL)')
Then, I tried the official example:
# wrong !
* def foo = 'hello #(name)'
# right !
* def foo1 = '#("hello " + name)'
* print foo1
* def name = 'test name'
* def temp = 'hello ' + name
* def foo2 = '#(temp)'
* print foo2
The result is :
#("select id from sr_sendreceive where batchnum =" + batchnum)
#("hello " + name)
#(temp)
回答1:
Sorry, the docs are wrong. This works for non-JSON only for match
. Like this:
* def batchnum = "112344552"
* def actual = 'select id from sr_sendreceive where batchnum = 112344552'
* match actual == '#("select id from sr_sendreceive where batchnum = " + batchnum)'
Inside JSON it will work:
* def foo = { bar: '#("select id from sr_sendreceive where batchnum = " + batchnum)' }
* print foo
Thanks for pointing this out, I will update the docs.
来源:https://stackoverflow.com/questions/56271303/as-for-rules-for-embedded-expressions-the-string-concatenation-does-not-work