Java進行時
                把握現在,成就未來!
          posts - 23,comments - 30,trackbacks - 0
          Velociy 1.6新增了一些非常有用的指令和功能,并修復了一些bug,用起來的確方便多了。這里我將列舉一些我們能夠直觀感受得到的一些改變.

          TYPE   
          CHANGE eg.
          ADD
          增加#define指令 定義可以引用的VTL渲染塊
          #define( $foo )Hello, $bar!#end
          #set( $bar = 'world')
          $foo 輸出: Hello, world!
          ADD
          增加可以跳出#foreach循環的#break指令 #foreac($a in $list)
            #if($a==1)
               #break
            #end
          #end
          ADD 增加#foreach指令中使用的VTL語法變量 $velocityHasNext判斷是否還有下一個元素
          #foreach( $customer in $customerList )
          $customer.Name #if( $velocityHasNext ), #end
          #end
          配置:
          directive.foreach.counter.name = velocityCount
          directive.foreach.iterator.name = velocityHasNext
          ADD
          允許模板中使用數組時當做List來使用,意味著可以使用list的方法
          $myarray.isEmpty()
          $myarray.size()
          $myarray.get(2)
          $myarray.set(1, 'test')
          ADD
          支持模板上調用變參數方法 對于public void setPlanets(String... planets)
          或者
          public void setPlanets(String[] planets)
          模板上可以這樣調用:
          $sun.setPlanets('Earth', 'Mars', 'Neptune')
          $sun.setPlanets('Mercury')
          $sun.setPlanets()
          ADD 增加嚴格引用檢查設置,必須在#set或者context中設置的變量才能使用,否則會拋出exception(可配置開啟關閉)
          如果$foo不存在,并且嚴格引用檢查開啟
          $foo ## Exception
          #set($bar = $foo) ## Exception
          #if($foo == $bar)#end ## Exception
          #foreach($item in $foo)#end ## Exception
          ADD 增加模板上定義map
          #set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"}) ## Map
          使用:
          $monkey.Map.get("banana")
          或 $monkey.Map.banana
          ADD
          增加#literal指令來指定大塊的不需要進行渲染的內容(類似于\(escaping)的多行版本用法)
          模板中:
          #literal()
          #foreach ($woogie in $boogie)
          nothing will happen to $woogie
          #end
          則輸出:
          #foreach ($woogie in $boogie)
          nothing will happen to $woogie
          #end



          #end
          ADD 增加#evaluate指令在模板渲染時動態執行字符串(類似于JS中的eval()方法)
          #set($source1 = "abc")
          #set($select = "1")
          #set($dynamicsource = "$source$select")
          ## $dynamicsource is now the string '$source1'
          #evaluate($dynamicsource)

          更多請查看 http://velocity.apache.org/engine/devel/changes-report.html

          也可以使用 http://velocity.apache.org/engine/devel/user-guide.html
          posted on 2008-12-31 17:27 biiau 閱讀(2069) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 乌鲁木齐县| 南充市| 永济市| 大竹县| 云南省| 湖口县| 屯昌县| 海门市| 武威市| 石楼县| 邵武市| 襄樊市| 潍坊市| 沐川县| 轮台县| 皮山县| 乌兰浩特市| 平度市| 尉氏县| 湖州市| 大港区| 隆尧县| 彭阳县| 广水市| 漳平市| 嘉义市| 广州市| 松原市| 西城区| 海口市| 香港| 仁布县| 桂林市| 高青县| 新平| 莱西市| 方城县| 长沙县| 安岳县| 拉萨市| 怀仁县|