zoukankan      html  css  js  c++  java
  • velocity的string转数字,numberTool

    velocity的string转数字,非常有意思:

    1、通过java的包装类进行转换

    #set($intString = "20")
    #set($Integer = 0)
    $Integer.parseInt($intString)

    #set($tring = "20")
    #set($Double = 0.0)
    $Double.parseDouble($string)

    以上输出:

    20

    20.0

    注意:velocity无法直接使用Integer(或Double),但是可以先定义一个整型变量(Double),使用这个整型变量的parseInt(“string”)转换。

    先定义,再使用!

    2、可以使用spring中的velocity的numberTool(numberToolAttribute属性):

        <bean id="velocityViewResolver"
              class="com.banksteel.erp.web.common.utils.VelocityLayoutViewResolver">
            <property name="layoutUrl" value="inc/layout.vm"/>
            <property name="cache" value="false"/>
            <property name="suffix" value=".vm"/>
            <property name="exposeSpringMacroHelpers" value="true"/>
            <property name="dateToolAttribute" value="dateTool"/>
            <property name="numberToolAttribute" value="numberTool"/>
            <property name="requestContextAttribute" value="req"/>
            <property name="exposeRequestAttributes" value="true"/>
            <property name="exposePathVariables" value="true"/>
            <property name="toolboxConfigLocation" value="WEB-INF/tool-box.xml"/>
            <property name="contentType" value="text/html;charset=UTF-8"/>
        </bean>

    $numberTool.format("0.00", "500");

    3、NumberTool

    org.apache.velocity.tools.generic.NumberTool

    在toolbox.xml中配置如下所示:

    <tool>
         <key>number</key>
         <scope>application</scope>
         <class>org.apache.velocity.tools.generic.NumberTool</class>
         <parameter name="format" value="#0.0"/>
    </tool>

    关于number,如下所示:

    函数举例显示结果:

    $number            org.apache.velocity.tools.generic.NumberTool@32c41c                            $number.currency("35")            ¥35.00                            $number.format            #0.0                            $number.locale            zh_CN                            $number.format("35")            35.0                            $number.integer("35.47")            35                            $number.number("35.47")            35.47                            $number.percent("0.3547")            35%                            $number.toNumber("35.47")            35.47         

    以上!

    注意:velocity的减法:“-”前后都要有空格!!!

  • 相关阅读:
    Towards Life-Long Autonomy of Mobile Robots Through Feature-Based Change Detection
    Magnetic field constraints and sequence-based matching for indoor pose graph SLAM
    3D Image-based Indoor Localization Joint With WiFi Positioning
    Online Probabilistic Change Detection in Feature-Based Maps
    Detectron2--(1)
    detectron2 + ubuntu + cpu
    出去上网-ubuntu-ss
    深度学习入门4
    IDM添加代理
    [转载]clover引导黑苹果icloud已达到账户数量限制解决方法
  • 原文地址:https://www.cnblogs.com/gmq-sh/p/4794009.html
Copyright © 2011-2022 走看看