云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > freemarker中文手册

freemarker中文手册

  • 62 次阅读
  • 3 次下载
  • 2025/5/31 17:57:22

开发笔记

截取字符

<#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中文手册 的文档
    • 收藏
    • 违规举报
    • 版权认领
    下载文档10.00 元 加入VIP免费下载
    推荐下载
    本文作者:...

    共分享92篇相关文档

    文档简介:

    开发笔记 截取字符 ${news.title} ${news.title[0..12]}... 一、freemarker的空值和默认值 ${user?if_exists} ${user?default('your name')} 判断对象是不是null Mouse found 或 Mouse found list 空值判断

    × 游客快捷下载通道(下载后可以自由复制和排版)
    单篇付费下载
    限时特价:10 元/份 原价:20元
    VIP包月下载
    特价:29 元/月 原价:99元
    低至 0.3 元/份 每月下载150
    全站内容免费自由复制
    VIP包月下载
    特价:29 元/月 原价:99元
    低至 0.3 元/份 每月下载150
    全站内容免费自由复制
    注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
    微信:fanwen365 QQ:370150219
    Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com