How to convert string into integer in the Velocity template?

后端 未结 4 1331
挽巷
挽巷 2020-12-29 01:37

I have a Velocity template file which has the data from XML. I want to convert the string into integer type.

How can I do that?

4条回答
  •  长情又很酷
    2020-12-29 02:05

    If you have some control over the velocity context, here's an alternative that alleviates the need to set a variable in the Velocity template.

    Context velocityContext = new Context();
    velocityContext.put(Integer.class.getSimpleName(), Integer.class);
    

    This allows you to call the static methods of java.lang.Integer in your template using $Integer.parseInt($value) and doesn't rely upon the #set having been called prior to performing the type conversion in the template.

提交回复
热议问题