How to convert string into integer in the Velocity template?

后端 未结 4 1315
挽巷
挽巷 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:25

    Aha! Been there.

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

    Doing this uses the java underlying velocity. The $Integer variable is nothing more that a java Integer object which you can then use to access .parseInt

    Edit: The above code is for demonstration. Of course there are ways to optimize it.

提交回复
热议问题