Groovy에서 "$ -Strings"의 중첩 된 평가를 수행하는 방법이 있습니다.
def obj = {["name":"Whatever", "street":"ABC-Street", "zip":"22222"]}
def fieldNames = ["name", "street", "zip"]
fieldNames.each{ fieldname ->
def result = " ${{->"obj.${fieldname}"}}" //can't figure out how this should look like
println("Gimme the value "+result);
}
결과는 다음과 같아야합니다
Gimme the value Whatever
Gimme the value ABC-Street
Gimme the value 22222
내 시도 (적절한 결과를 제공하지 않는 중이 문제를 해결하기 위해 예를 들어 단지 obj.street} 또는 전혀 컴파일되지 않습니다 나는 단순히 천국 '. . http://groovy.codehaus.org/Strings+and+GString 나는 그것이 가능해야한다 생각 해당 페이지 당신이 그것을 할 수있을 거라고 생각하게 중첩 된 사례가 없습니다
https://stackoverflow.com/questions/46326920/how-to-use-groovy-template-engine-when-template-name-is-a-variable 변수의 진정한 사용 사례처럼 보입니다. – sorin