`

FreeMarker

 
阅读更多
一目了然的数据模型
As you have seen, the data-model is basically a tree.正如你所看到的,数据模型基本上是一个树。 This tree can be arbitrarily complicated and deep, for example:这种树可以任意复杂和深刻的,例如:

  
(root) (根)
  | |
  +- animals + - 动物
  | | | |
  | +- mouse | + - 鼠标
  | | | | | |  
  | | +- size = "small" | | + - 大小=“小”
  | | | | | |  
  | | +- price = 50 | | + - 价格= 50
  | | | |
  | +- elephant | + - 大象
  | | | | | |  
  | | +- size = "large" | | + - 大小=“大”
  | | | | | |  
  | | +- price = 5000 | | + - 价格= 5000
  | | | |
  | +- python | + - 蟒蛇
  | | | |  
  | +- size = "medium" | + - 尺寸=“中等”
  | | | |  
  | +- price = 4999 | + - 价格= 4999
  | |
  +- test = "It is a test" + - 测试=“这是一个测试”
  | |
  +- whatnot + - 诸如此类
      | |
      +- because = "don't know" + - 因为“不知道”  
 
  

The variables that act as directories (the root, animals , mouse , elephant , python , whatnot ) are called hashes .充当目录(根, 动物 , 老鼠 , 大象 , 蟒蛇 , 诸如此类 )被称为哈希变量。 Hashes store other variables (the so called哈希存储其他变量(即所谓的 subvariables ) by a lookup name (eg, "animals", "mouse" or "price").查找名称(如“动物”,“鼠标”或“价格”) 的子变量) 。

The variables that store a single value ( size , price , test and because ) are called scalars .存储一个值( 尺寸 , 价格 , 测试和因为 )的变量被称为标量 。

When you want to use a subvariable in a template, you specify its path from the root, and separate the steps with dots.当您要使用的模板中的一个子变量,从根本上指定其路径,并用点分开的步骤。 To access the price of a mouse , you start from the root and go into animals , and then go into mouse then go into price .要访问鼠标的价格,从根开始, 进入动物,然后进入鼠标然后进入价格。 So you write animals.mouse.price .所以,你写animals.mouse.price。 When you put the special ${ ... } codes around an expression like this, you are telling FreeMarker to output the corresponding text at that point.当你把周围表达这样的特殊的$ {...}代码,你告诉FreeMarker的输出在这一点上相应的文本。

There is one more important kind of variable: sequences .还有一个更重要的一种变量: 序列 。 They are similar to hashes, but they don't store names for the variables they contain.它们类似于哈希,但他们不存储它们所包含的变量的名称。 Instead, they store the subvariables sequentially, and you can access them with a numerical index.相反,他们的子变量存储顺序,您可以访问数字索引。 For example, in this data-model, animals and whatnot.fruits are sequences:例如,在这个数据模型, 动物和whatnot.fruits序列:

  
(root) (根)
  | |
  +- animals + - 动物
  | | | |
  | +- (1st) | + - (第1)
  | | | | | |
  | | +- name = "mouse" | | + - 名称=“鼠标”
  | | | | | |
  | | +- size = "small" | | + - 大小=“小”
  | | | | | |
  | | +- price = 50 | | + - 价格= 50
  | | | |
  | +- (2nd) | + - (第2)
  | | | | | |
  | | +- name = "elephant" | | + - 名称=“大象”
  | | | | | |
  | | +- size = "large" | | + - 大小=“大”
  | | | | | |
  | | +- price = 5000 | | + - 价格= 5000
  | | | |
  | +- (3rd) | + - (第3)
  | | | |
  | +- name = "python" | + - 名称=“蟒蛇”
  | | | |
  | +- size = "medium" | + - 尺寸=“中等”
  | | | |
  | +- price = 4999 | + - 价格= 4999
  | |
  +- whatnot + - 诸如此类
      | |
      +- fruits + - 水果
          | |
          +- (1st) = "orange" + - (第1)=“橙”
          | |
          +- (2nd) = "banana" + - (第二)=“香蕉”  
 
  

To access a subvariable of a sequence you use a numerical index in square brackets.要访问您使用方括号中的数字索引的一个序列的子变量。 Indexes start from 0 (it's a programmer tradition to start with 0), thus the index of the first item is 0, the index of the second item is 1, and so on.索引从0(从0开始,这是一个程序员的传统)开始,因此该指数的第一个项目是0,第二项的索引是1,依此类推。 So to get the name of the first animal you write animals[0].name .所以获得的第一个动物的名称, 你写的动物[0]。名称。 To get the second item in whatnot.fruits (which is the string "banana" ) you write whatnot.fruits[1] .在whatnot.fruits要获得的第二项(这是字符串“香蕉”),你写whatnot.fruits [1] 。

Scalars can be further divided into these categories:标量可进一步分为这些类别:

String: Text, that is, an arbitrary sequence of characters such as ''m'', ''o'', ''u'', ''s'', ''e'' above.字符串:文本,这是一个任意的字符,如序列“米”,“O”,“ü”,“S”,“E”上面。 For example the name -s and size -s are strings above.例如名称 - S和大小 - S是字符串以上。

Number: It's a numerical value, like the price -s above.编号:像s以上的价格 ,这是一个数值。 The string "50" and the number 50 are two totally different things in FreeMarker.字符串“50”和50号是两个完全不同的东西在FreeMarker。 The former is just a sequence of two characters (which happens to be readable as a number for humans), while the latter is a numerical value that you can use, say, in arithmetical calculations.前者仅仅是两个字符的序列(这恰好是一些对人类可读),而后者则是一个数值,您可以使用,例如在算术计算,。

Date/time: A date or time.日期/时间:日期或时间。 Like the date an animal were captured, or the time the shop opens.日期一样的动物被抓获,或打开店铺的时间。

Boolean: A true/false (yes/no, on/off, etc.) thing.布尔:一个真/假(是/否,开/关,等)的事情。 Like animals could have a protected subvariable, which store if the animal is protected or not.喜欢的动物可能有一个受保护的子变量,它存储如果动物是保护或不保护。

Summary:摘要:

The data-model can be visualized as a tree.数据模型可以可视化树。

Scalars store a single value.标量存储一个值。 The value can be a string or a number or a date/time or a boolean.该值可以是一个字符串或一个数字或日期/时间或布尔。

Hashes are containers that store other variables and associate them with a unique lookup name.哈希存储其他变量和一个独特的查找名称相关联的容器。

Sequences are containers that store other variables in an ordered sequence.序列是一个有序的序列,存储在其他变量的容器。 The stored variables can be retrieved via their numerical index, starting from 0.检索存储的变量可以通过其数字索引,从0开始。
分享到:
评论

相关推荐

    freemarker语法完整版

    Freemarker页面语法 A 概念 最常用的 3 个概念 sequence 序列,对应java 里的list 、数组等非键值对的集合 hash 键值对的集合 namespace 对一个ftl 文件的引用, 利用这个名字可以访问到该ftl 文件的资源 ...

    freemarker-2.3.31-API文档-中文版.zip

    赠送jar包:freemarker-2.3.31.jar; 赠送原API文档:freemarker-2.3.31-javadoc.jar; 赠送源代码:freemarker-2.3.31-sources.jar; 赠送Maven依赖信息文件:freemarker-2.3.31.pom; 包含翻译后的API文档:...

    freemarker-2.3.30-API文档-中文版.zip

    赠送jar包:freemarker-2.3.30.jar; 赠送原API文档:freemarker-2.3.30-javadoc.jar; 赠送源代码:freemarker-2.3.30-sources.jar; 赠送Maven依赖信息文件:freemarker-2.3.30.pom; 包含翻译后的API文档:...

    安装freemarker插件(freemarker的eclipse插件)

    安装freemarker插件(freemarker的eclipse插件) a) 首先下载 freemarker-ide-0.9.14.zip(在这里不用下载了,附件中已经有了) b) 解压后:把hudson.freemarker_ide_0.9.14这个文件放到:eclipse\plugins下面 c) 发现...

    freemarker

    一篇freemarker很不错的文章 reeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成: 1,文本:直接输出的部分 2,注释:格式部分,不会输出 3,插值:即${...}或#{...}格式的部分,将使用...

    超完整FreeMarker中文教程,代码

    什么是FreeMarker? ................................................................................................. 7 我们应该阅读什么内容? .............................................................

    JAVA项目代码绘制PDF和通过freemarker动态生成PDF

    3. freemarker(FreemarkerUtils) 对于没有使用宏、函数等word、excel,需要按模板动态生成word、excel、html,只需要一个freemarker,先将word、excel、html等另存为**xml**,即可使用模板动态生成文件,目前xlsx是...

    freemarker模板技术生成复杂word文档---解决了编码问题

    大致的思路是先用office2003或者2007编辑好word的样式,然后另存为xml,将xml翻译为FreeMarker模板,最后用java来解析FreeMarker模板并输出‘.doc’ word文档。经测试这样方式生成的word文档完全符合office标准,...

    freemarker-2.3.30-API文档-中英对照版.zip

    赠送jar包:freemarker-2.3.30.jar; 赠送原API文档:freemarker-2.3.30-javadoc.jar; 赠送源代码:freemarker-2.3.30-sources.jar; 赠送Maven依赖信息文件:freemarker-2.3.30.pom; 包含翻译后的API文档:...

    FreeMarker_Programmer Guide

    FreeMarker

    Java项目中利用Freemarker模板引擎导出--生成Word文档

    基于Java语言来导出Word文档的方式也有很多种,如Jacob,Apache POI,Freemarker,PageOffice,java2word 等等。。。。 在这里将通过Freemarker这个模板引擎来实现导出 Word,项目不限于Swing,SSH,SSM,Spring ...

    eclipse的freemarker插件

    freemarker格式化的eclipse插件。用于freemarker的格式化。

    freemarker替换变量实例

    freemarker替换变量实例

    超强freemarker使用总结,有示例有讲解,可做快速查询手册!!

    在开发web项目的时候使用到的页面展现技术,它并...总体,该文档能够提供所有常用的freemarker操作,示例和简略的讲解可以让人一下子就能上手,效率极高。 适合做快速查阅册子,同时也非常适合初学者和骨灰开发者使用。

    freemarker-2.3.23-API文档-中文版.zip

    赠送jar包:freemarker-2.3.23.jar; 赠送原API文档:freemarker-2.3.23-javadoc.jar; 赠送源代码:freemarker-2.3.23-sources.jar; 赠送Maven依赖信息文件:freemarker-2.3.23.pom; 包含翻译后的API文档:...

    FreeMarker中文文档.pdf下载

    FreeMarker中文文档.pdf FreeMarker入门必修

    用Freemarker生成word文档

    2.将xml中需要动态修改内容的地方,换成freemarker的标识符 添加图片 如果你需要在word中添加图片,那你就在第一步制作模板时,加入一张图片占位,然后打开xml文档,可 以看到如下的一片base64编码后的代码: ...

    hudson.freemarker_ide_0.9.14

    FreeMarker在Eclipse安装 1.将插件hudson.freemarker_ide_0.9.14文件夹放到eclipse下的plugins文件夹下 按理,这样的话,重启eclipse就应该解决了 但是不成 因为hudson.freemarker_ide_0.9.14文 件夹下的...

Global site tag (gtag.js) - Google Analytics