Freemarker学习笔记(1)

定义:

一个生成文本输出的模板引擎,但不是一个web框架(FreeMarker is a template engine: a generic tool to generate text output )

FreeMarker is not a Web application framework. It is suitable as a component in a Web application framework, but the FreeMarker engine itself knows nothing about HTTP or servlets. It simply generates text. As such, it is perfectly usable in non-web application environments as well. Note, however, that we provide out-of-the-box solutions for using FreeMarker as the view component of Model 2 frameworks such as Struts.

方法:Template + data model = output

DataModel:

(root)
  |
  +- animals(hashes)
  |   |
  |   +- mouse
  |   |   |   
  |   |   +- size = "small"( scalars)
  |   |   |   
  |   |   +- price = 50
  |   |
  |   +- elephant
  |   |   |   
  |   |   +- size = "large"
  |   |   |   
  |   |   +- price = 5000
  +- whatnot
      |
      +- fruits(sequences)
          |
          +- (1st) = "orange"
          |
          +- (2nd) = "banana"

1。The variables that act as directories (the root, animals, mouse, ) are called hashes. Hashes store other subvariables by a lookup name.

2。The variables that store a single value (size, price) are called scalars.

3。similar to hashes, but they don't store names for the variables they contain

The template

FTL tags:

if-else 指令

<#if animals.python.price < animals.elephant.price>
  Pythons are cheaper than elephants today.
<#else>
  Pythons are not cheaper than elephants today.
</#if>  
list指令
  
  
<p>We have these animals:
<table border=1>
  <tr><th>Name<th>Price
  <#list animals as being>
  <tr><td>${being.name}<td>${being.price} Euros
  </#list>
</table>
include指令
注意:
区分大小写;指令不能嵌套;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值