velocity中的velocityCounter不起作用的原因

2014-11-24 10:36:25 · 作者: · 浏览: 0

今天用org.springframework.ui.velocity.VelocityEngineFactoryBean 时,velocityCounter这个变量的时候死活不起作用,折腾了良久也不行,网上也找不到任何资料。以前用原生态不与spring集成时还没有问题呢,没办法,只有规规矩矩的把源码下载下来跟跟看了。

最后却发现是原来是配置文件的原因

一部分部分源码

[java]
RuntimeConstants

/** Counter reference name in #foreach directives. */
String COUNTER_NAME = "directive.foreach.counter.name";

org.apache.velocity.runtime.directive.Foreach


counterName = rsvc.getString(RuntimeConstants.COUNTER_NAME);
counterName = rsvc.getString(RuntimeConstants.COUNTER_NAME);
hasNextName = rsvc.getString(RuntimeConstants.HAS_NEXT_NAME);
counterInitialValue = rsvc.getInt(RuntimeConstants.COUNTER_INITIAL_VALUE);
if (!"velocityCount".equals(counterName))

RuntimeConstants

/** Counter reference name in #foreach directives. */
String COUNTER_NAME = "directive.foreach.counter.name";

org.apache.velocity.runtime.directive.Foreach


counterName = rsvc.getString(RuntimeConstants.COUNTER_NAME);
counterName = rsvc.getString(RuntimeConstants.COUNTER_NAME);
hasNextName = rsvc.getString(RuntimeConstants.HAS_NEXT_NAME);
counterInitialValue = rsvc.getInt(RuntimeConstants.COUNTER_INITIAL_VALUE);
if (!"velocityCount".equals(counterName))
原来这个是变量名可以配置的,而我的配置文件

[java]




class
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader

loopCounter
1
true
50
UTF-8
UTF-8






class
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader

loopCounter
1
true
50
UTF-8
UTF-8



配置成了loopCounter,所以必须用loopCounter才行。