2
我寫了使用#foreach
指令的相當基本的Velocity模板。當我運行它,我在日誌中得到以下信息:Velocity中不推薦使用的屬性
[提醒]在directive.foreach.iterator.name物業已經 棄用。它將在Velocity 2.0中被刪除(以及$ velocityHasNext本身) 。相反,請使用$ foreach.hasNext從現在開始訪問此 值。
但問題是,我至少明確地不使用此屬性。我只是使用#foreach
循環的基本形式,完全如user guide所示。
下面是產生此日誌警告的簡單代碼。速度版本是1.7。
final Properties properties = new Properties();
VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.init(properties);
StringWriter stringWriter = new StringWriter();
Map<String, Object> velocityVars = new HashMap<>();
List<Date> dates = new ArrayList<>();
dates.add(new Date());
dates.add(new Date());
velocityVars.put("dates", dates);
VelocityContext velocityContext = new VelocityContext(velocityVars);
String template =
"foo\n" +
"#foreach($d in $dates)\n" +
" $d\n" +
"#end \n" +
"bar";
velocityEngine.evaluate(velocityContext, stringWriter, "blah", template);
System.out.println(stringWriter.toString());
所以,問題是 - 這是爲什麼警告記錄以及如何構建我的代碼,以防止它出現?
謝謝!順便說一句,#2的建議不起作用。爲這些屬性指定空字符串會給出相同的警告。看起來處理默認值並不是Velocity最強大的一面。 – mindas