第一范文网 - 专业文章范例文档资料分享平台

freemarker中文手册

来源:用户分享 时间:2025/5/24 11:34:00 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

开发笔记

截取字符

<#if news.title?length lt 13 > ${news.title}

<#else>

${news.title[0..12]}...

一、freemarker的空值和默认值

${user?if_exists}

${user?default('your name')}

判断对象是不是null <#if mouse?exists> Mouse found <#else>

或<#if book.name?? >

Mouse found

list 空值判断 <#if bookList?size = 0>

<#list recommendlist as content> <#if content_index%3==0>

<#if content_index%3==1>

  • ${content.title}
  • <#if content_index%3==2>

  • ${content.title}
  • <#list recommendlist as content> <#if content_index%3==0>

    font-weight:bold; font-size:14px;

    List指令还隐含了两个循环变量:

    item_index:当前迭代项在所有迭代项中的位置,是数字值。

    item_has_next:用于判断当前迭代项是否是所有迭代项中的最后一项。

    在循环过程中,如果您想跳出循环,那么可以使用结合break指令,即<#break>来完成。 <#escape x as (x)!\ //去除null报错

    三、 Freemarker如何遍历List实例应用

    创通过上面的介绍,相信您已经对Freemarker如何遍历List有了了解,那么我们就废话少说,开始做一个应用吧。 User类

    public class User{ private String username; private

    (省略set和get方法) } user.ftl

    <#--Freemarker遍历list--> 简单遍历list: <#list userList as user> 用户名:${user.userName} 密 码:${user.userPassword} 年 龄: ${user.age}

    <#--Freemarker遍历list并应用list隐含变量item_index--> item_index使用: <#list userList as user> 第${user_index+1}个用户 用户名:${user.userName} 密 码:${user.userPassword}

    年 龄: ${user.age}

    <#--Freemarker遍历list并应用list隐含变量item_has_next--> item_has_next,size使用: <#list userList as user> 用户名:${user.userName} 密 码:${user.userPassword} 年 龄: ${user.age} <#if !user_has_next>

    共有${userList?size}最后一个用户是:${user.userName}

    <#--Freemarker遍历list并按用户年龄升序排序--> 按用户年龄升序排序:

    <#list userList?sort_by(\ 用户名:${user.userName} 密 码:${user.userPassword} 年 龄: ${user.age}

    <#--Freemarker遍历list并按用户年龄降序排序--> 按用户年龄降序排序:

    <#list userList?sort_by(\ 用户名:${user.userName} 密 码:${user.userPassword} 年 龄: ${user.age}

    <#--Freemarker遍历list当用户年龄大于21岁时,停止输出--> list中应用break:

    <#list userList?sort_by(\ 用户名:${user.userName} 密 码:${user.userPassword} 年 龄: ${user.age} <#if (user.age>21) > <#break>

    1、快速入门

    (1)模板 + 数据模型 = 输出

    ? FreeMarker基于设计者和程序员是具有不同专业技能的不同个体的观念

    ? 他们是分工劳动的:设计者专注于表示——创建HTML文件、图片、Web页面

    的其它可视化方面;程序员创建系统,生成设计页面要显示的数据

    ? 经常会遇到的问题是:在Web页面(或其它类型的文档)中显示的信息在设计页面时是无效的,是基于动态数据的

    ? 在这里,你可以在HTML(或其它要输出的文本)中加入一些特定指令,FreeMarker会在输出页面给最终用户时,用适当的数据替代这些代码 ? 下面是一个例子:

    Welcome!

    Welcome ${user}!

    Our latest product: !

    搜索更多关于: freemarker中文手册 的文档
    freemarker中文手册.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
    本文链接:https://www.diyifanwen.net/c9fjlz4cvmn9uewu2soeb_1.html(转载请注明文章来源)
    热门推荐
    Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
    声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
    客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
    渝ICP备2023013149号
    Top