簡體   English   中英

如何使用Groovy腳本引擎替換三元運算中的變量

[英]How to replace variable inside ternaryoperation using groovy script engine

我正在使用Groovy SimpleTemplateEngine在運行時動態設置值。 我也在字符串中使用三元運算符。 三元運算符中變量的值不會更新。 有人可以幫忙實現這一目標嗎?

File f = new File("test.txt");
        SimpleTemplateEngine engine = new SimpleTemplateEngine();
        Template template = engine.createTemplate(f);
        def refMap = [:]
        refMap["condition1"] = "true";
        refMap["acctNbr"] = "1234567890";
        refMap["value"] = "abc";
        println template.make(refMap).toString();

test.txt

<acctNbr13>${acctNbr}</acctNbr13>
${(
Boolean.parseBoolean(condition1)
?
'''
<test>${value}</test>
'''
:
''
)}

我懷疑字符串已經代表了替換后的值,並且自身未得到解析。

它適合您更換嗎

 '''
 <test>${value}</test>
 '''

 '<test>' + value + '</test>'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM