Velocityの浅い分析とJsp、Freemarkerとの比較

3622 ワード

Velocity      java      (template engine).            web      java              。   Web designers  java      MVC   (Model-View-Controller )    ,    Web designers                     , Java                  java          —–Velocity          .
     jsp、PHP      ,Velocity                 java   ,      web site        .
Apache            Turbine   Velocity        true MVC model.
 、       Velocity    (VTL)
1、VTL   ( statement),   VTL statement    #  ,        ,          , the Velocity Templating Engine          #   ,        VTL                ,   #            VTL   .
2、VTL  :      ##        .        ,     #*  *# 
3、Velocity references  java                       VTL.
       VTL    java    java bean           java    Context                —  ,  java                  .
4、References(  )
VTL     references:    (variables),    (properties)     (methods).       VTL     ,     java                   (  $    )       !  ,   java                       .
                  .         $foo         int, Velocity engine          .toString()              (int).
  :           java Bean   getter/setter    ,    java               , $foo.Name     class Foo’s getName()      ,      Foos   public Name       .
5、  (directives)
       “  “      ,   (directives) –                java  —                 .
     #            .
  :set   ,                      null,         ,     VTL         .    :
#set( $result = $query.criteria(“name”) )
The result of the first query is $result
#set( $result = $query.criteria(“address”) )
The result of the second query is $result
  $query.criteria(“name”)        ”bill”,  $query.criteria(“address”)   null,   TVL       :
The result of the first query is bill
The result of the second query is bill
6、   #literal             ,  :
#literal()
#foreach ($woogie in $boogie)
nothing will happen to $woogie
#end
#end
   ::
#foreach ($woogie in $boogie)
nothing will happen to $woogie
#end
7、            
    ,            . Velocity                 .       
         .                ,Velocity          .  
$customer.address    ,     :
1. getaddress()
2. getAddress()
3. get(“address”)
4. isAddress()
  VTL       Address   ,  :
1. getAddress()
2. getaddress()
3. get(“Address”)
4. isAddress()
8、Velocity  ==    
  :==   java  ==      :            (       )Velocity             numbers,strings  ,orobjects toString()      .        ,      toString()       .
9、 Velocity        ,       :
(1)、   Velocity
  (2)、  context  
(3)、     context
(4)、    
(5)、       ,      
 、Velocity Jsp、Freemarker   
 java  ,          :jsp、freemarker、velocity。
jsp          
  : 
1、    ,   java   
2、  jsp  (jsp tag) 
3、       (el) 
4、    ,    ,      jsp    
5、    。jsp   class    ,         
  : 
jsp      ,         ,      java  ,         mvc  。
velocity          jsp      
  : 
1、    java  ,       mvc   
2、    ,   jsp       
3、       ,  jsp         velocity  
  : 
1、       
2、             jsp 。 
3、 jsp       
freemarker 
  : 
1、    java  ,       mvc   
2、       
3、 jsp       
4、        ,       
5、   (  jsp  )     
6、        
  : 
1、       
2、             jsp 
  :velocity      ,   jsp,     freemarker    ,        (      、       )    ,freemarker      tag el jsp