Velocity script Summary

Source: Internet
Author: User

Guidance:
  Velocity:
Rationale:
$ Username and $! The difference between username. When the username cannot be found, $ username returns the string "$ username", while $! Username returns an empty string ""
So: # Set ($! Username = ') determines whether the string is null.
  The following is the summary of the velocity script.
1,Declaration: # Set ($ Var = xxx)
The following content can be left
Variable reference
String Literal
Property Reference
Method reference
Number literal # Set ($ I = 1)
Arraylist # Set ($ arr = ["yt1", "T2"])
Technical Arithmetic Operators
2,Note:
Single line ## xxx
Multiple rows
#*
Xxx
Xxxx
Xxxxxxxxxxxx
*#
References reference type
3,Variable Variables
It must start with "$" and the first character must be a letter. Character followed by a VTL identifier. (A. Z
Or a. Z ).
A variable can contain the following characters:
Alphabetic (A. Z, A. Z)
Numeric (0 .. 9)
Hyphen ("-")
Underscore ("_")
4,Properties
$ Identifier. identifier
$ User. Name
NAME value in hashtable user. For example: User. Get ("name ")
5,Methods
Object User. getname () = $ user. getname ()
6,Formal reference notation
Use {} to separate variable names from strings
For example
# Set ($ user = "CSY "}
$ {User} Name
Return csyname
$ Username
$! Username
$ And $! Difference
When the username cannot be found, $ username returns the string "$ username", while $! Username returns an empty string ""
7,Double quotation marks and quotation marks
# Set ($ Var = "HELO ")
Test "$ Var" returns testhello
Test' $ var 'returns test' $ var'
You can change the default processing mode by setting stringliterals. interpolate = false.
8,Condition Statement
# If ($ Foo)
  Velocity!
# End
# If ($ Foo)
# Elseif ()
# Else
# End
When $ foo is null or a Boolean object's false value, it is executed.
9,Logical OPERATOR: ==&||!
10,Loop statement # foreach ($ VaR in $ arrays)// The set contains the following three vectors: A hashtable or an array
# End
# Foreach ($ product in $ allproducts)
  

  • $ Product
  • # End
    # Foreach ($ key in $ allproducts. keyset ())
      

  • Key: $ key-> value: $ allproducts. Get ($ key)
  • # End
    # Foreach ($ customer in $ customerlist)
      
    $ Velocitycount$ Customer. Name

    # End
    11,The velocitycount variable is defined in the configuration file.
    # Default name of the loop counter
    # Variable reference.
    Directive. foreach. Counter. Name = velocitycount
    # Default starting value of the loop
    # Counter variable reference.
    Directive. foreach. Counter. Initial. value = 1
    12,Include files
    # Include ("one.gif", "two.txt", "three.htm ")
    13,Parse import script
    # Parse ("me. VM ")
    14,# Stop stop execution and return
    15,Define the macro velocimacros, which is equivalent to the function supporting the inclusion Function
    # Macro (d)
      

    # End
    Call
    # D ()
    16,Macro with Parameters
    # Macro (tablerows $ color $ somelist)
    # Foreach ($ something in $ somelist)
      
    $ Something

    # End
    # End
    17,Range Operator
    # Foreach ($ Foo in [1 .. 5])
      
    Posted @ 2008-06-18 square inch reading (24) | comment (0) | Edit

    This article is transferred from
    Http://www.cnblogs.com/wllyy189/

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.