• velocity中的velocityCounter不起作用的原因


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

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

    一部分部分源码

    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))


    原来这个是变量名可以配置的,而我的配置文件

    <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
    		<property name="resourceLoaderPath" value="classpath*:template" />
            <property name="velocityProperties">
    			<props>
    				<prop key="resource.loader">class</prop>
    				<prop key="class.resource.loader.class">org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader</prop>
    				<prop key="velocimacro.library" />
    				<prop key="directive.foreach.counter.name">loopCounter</prop>
    				<prop key="directive.foreach.counter.initial.value">1</prop>
    				<prop key="file.resource.loader.cache">true</prop>
    				<prop key="parser.pool.size">50</prop>
    				<prop key="input.encoding">UTF-8</prop>
    				<prop key="output.encoding">UTF-8</prop>
    			</props>
    		</property>
        </bean>


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

  • 相关阅读:
    Windows与Linux端口占用查询及处理
    mysql的五种日期和时间类型【转载】
    MongoDB的管理
    在MongoDB中执行查询、创建索引
    MongoDB文档的基本操作
    Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) ABCD
    CNN卷积神经网络
    hdu6406 Taotao Picks Apples 多校第8场1010
    hdu6397 Character Encoding 多校第8场1001
    梯度下降和反向传播
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3149534.html
Copyright © 2020-2023  润新知