我有一个 java 字符串,它基本上是一个速度模板。String vt = "#foreach ($number in [1..34]) $number += $number #end"String result = *String_vt_calculated_by_Velocity_Engine*;System.out.println(result);如何在 Java 中评估上述字符串并获得结果?
2 回答
GCT1015
TA贡献1827条经验 获得超4个赞
您必须使用Velocity.Evaluate检查此文档
import java.io.StringWriter;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
public class LoadTemplateFromStringTest {
public static void main(String[] args) {
VelocityContext context = new VelocityContext();
StringWriter sw = new StringWriter();
String vt = "#foreach ($number in [1..34]) $number += $number #end";
Velocity.evaluate( context, sw, "", vt);
System.out.println(sw);
}
}
添加回答
举报
0/150
提交
取消