velocity常用操作

1.取值
$!{data.totalCount}
$item.id
2.循环
#foreach(${item} in $!{data.result})
#end
3.时间格式
$!dateTool.format("yyyy-MM-dd",$!{item.Info.registerTime})
#if($!{item.createTime})
   $dateTool.format("yyyy年MM月dd日",${item.createTime})
#end


spring mvc配置


    <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath">
            <value>/WEB-INF/vm</value>
        </property>
        <property name="velocityProperties">
            <props>
                <prop key="input.encoding">UTF-8</prop>
                <prop key="output.encoding">UTF-8</prop>
                <prop key="velocimacro.library">common/macro.vm</prop>
            </props>
        </property>
        <property name="configLocation" value="classpath:/velocity.properties"/>
    </bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
        <property name="layoutUrl" value="/layout/default.vm"/>
        <property name="screenContentKey" value="unes_screen_content" />
        <property name="suffix">
            <value>.vm</value>
        </property>
        <property name="exposeSpringMacroHelpers" value="true"/>
        <property name="dateToolAttribute" value="dateTool"/>
        <property name="numberToolAttribute" value="numberTool"/>
        <property name="contentType">
            <value>text/html;charset=UTF-8</value>
        </property>
    </bean>

猜你喜欢

转载自bitcarter.iteye.com/blog/2280963
今日推荐