velocity一些用法(不是uesrguide).doc

  1. 1、本文档共8页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
velocity一些用法(不是uesrguide)

velocity一些用法(不是uesrguide) 近期研究一下eclipse的代码生成.在两个模板中间决择.网上一查发现全是说FREEMARKER好的.而且还拿出来强有例的对比的表格. 但是,对比的对象……velocity基本上就是1.0的初初级版. 这个对比.简直就好象是韦小宝学习韦陀掌的招式,来跟普通的少林弟子过招,就算是人家用长拳,韦小宝当然也打不过啦…. 有点扯远了…呵呵 Velocity还是一个不错的开源项目.其实,一般开源项目,只要持续的更新.那么就算开始的时候多么的垃圾多么的不完善.也终会成大器的.hibernate是这样,mysql 是这样.. 网上写的例子一般都是TVM的模板.而且还是有些例子完成不能运行的… 这些不说了. 大家直接看velocity 官网的userguide就好了..比网上写的还全.而且主要是人家跟最新的velocity是对应的,是可以运行的. 上来先来一个大家都常见的就是把一个list里的东西,转成aaa, bbb , ccc 注意最后的这个没有”,” 我记得我以前也是被这个问题困扰了好久. #foreach 会生成包含$products 中对象的一个列表. 每一次循环都会将列表中的一个对象赋与变量 $product . $allProducts 或以是一个 Vector, a Hashtable or an Array 类型的容器. 指定给变量 $product 是 一个引用到其中一个 java 对象的引用. For example, if $product 确实是一个 java 代码中的 Product class i,它可以这样的方法访问$product.Name method (ie: $Product.getName()). 我们假设 $allProducts 是一个 Hashtable.看看取出其中的东东多么简单: ul #foreach( $key in $allProducts.keySet() ) liKey: $key - Value: $allProducts.get($key)/li #end /ul 通过引用变量$velocityCount 可以访问到 Velocity 提供的计数器: table #foreach( $customer in $customerList ) trtd$velocityCount/tdtd$customer.Name/td/tr #end /table 但是官网上的例子这样写道: Velocity provides an easy way to get the loop counter so that you can do something like the following: table #foreach( $customer in $customerList ) trtd$foreach.count/tdtd$customer.Name/td/tr #end /table 这个小例子.真的是憋倒一堆人呀....还以为在freemarker里好实现在vm里不好写呢..结果,这么容易.... Velocity also now provides an easy way to tell if you are on the last iteration of a loop: #foreach( $customer in $customerList ) $customer.Name#if( $foreach.hasNext ),#end #end 为什么让这个有名的小例子全面运行. 给一个完整的TEST吧. /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * License); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * /licenses/LICENSE-2.0 * *

文档评论(0)

yan698698 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档