【freemarker】渲染列表一系列操作
数据模型:
public class AddressVo implements Serializable { private static final long serialVersionUID = 1137197211343312155L; private String name; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public AddressVo(String name) {
this.name = name;
} public AddressVo() {
}
}
public class UserVo implements Serializable { private String name;
private Integer age; private List<AddressVo> addressVoList; private Date birthday; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
} public List<AddressVo> getAddressVoList() {
return addressVoList;
} public void setAddressVoList(List<AddressVo> addressVoList) {
this.addressVoList = addressVoList;
} public Date getBirthday() {
return birthday;
} public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
@GetMapping("list")
public String list(Model model){ List<UserVo> userVoList=new ArrayList<>();
for (int i=0;i<5;i++){
UserVo userVo=new UserVo();
userVo.setName("张三"+i);
if(i!=3){
userVo.setAddressVoList(Arrays.asList(new AddressVo("上海"+i),new AddressVo("北京"+i)));
}
userVo.setAge(i*5);
if(i!=2){
userVo.setBirthday(DateTime.now().plusDays(i).toDate());
}
userVoList.add(userVo);
}
model.addAttribute("userList",userVoList);
return "userList";
}
freemarker模板
<table style="width: 1000px;height: auto" cellpadding="1" cellspacing="1">
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>地址</th>
<th>生日</th>
<th>操作</th>
</tr>
</thead>
<#list userList as user >
<tr>
<#--防止user里没有name-->
<td>${user.name!}</td>
<td>${user.age!}</td>
<td>
<#--防止user的addressVoList为空-->
<#list user.addressVoList!>
<#items as address>
${address.name!} <#sep >,
</#items>
<#else >无地址
</#list>
</td>
<td>
${(user.birthday?string("yyyy-MM-dd"))!"日期不存在"}
</td>
<td>
<#if user?is_even_item>偶数
<#else> 奇数
</#if>
${user?counter}
</td>
</tr>
</#list>
</table>
展示:
1、freemarker格式化日期防止为空导致异常。
2、freemark遍历列表防止值为空导致异常。
【freemarker】渲染列表一系列操作的更多相关文章
- React.js 小书 Lesson13 - 渲染列表数据
作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson13 转载请注明出处,保留原文链接和作者信息. 列表数据在前端非常常见,我们经常要处理这种类型 ...
- 问题:JFinal框架使用FreeMarker渲染视图报错
本人用的是JFinal-3.4. 问题描述: 在JFinal框架中使用FreeMarker渲染视图时,报 Caused by: java.lang.ClassNotFoundException: fr ...
- itextpdf freemarker渲染
现有需求涉及到打印pdf操作,简单找了俩种方式 在现有的模板上进行编辑,操作难度比较大 通过freemarker生成静态页面,在进行转换html,完美. 关于动态生成pdf,网上参考的挺多的,看来看去 ...
- 为什么你需要在用 Vue 渲染列表数据时指定 key
本文改写整理自一篇博文,原文链接如下: Why you should use the key directive in Vue.js with v-for Application state and ...
- python学习04——列表的操作
笨办法学python第38节 如何创建列表在第32节,形式如下: 本节主要是讲对列表的操作,首先讲了 mystuff.append('hello') 的工作原理,我的理解是,首先Python找到mys ...
- (转载)Python 列表(list)操作
(转载)http://blog.csdn.net/facevoid/article/details/5338048 创建列表sample_list = ['a',1,('a','b')] Python ...
- Python基础学习8---list列表的操作
a_list = ['hello','world',1,'shanghai',3.99] #列表添加操作的4种方法 #1. 通过+ 字符来拼接 a_list = a_list + [1,'wuhan' ...
- 用Vue实现状态列表的操作涵盖所有的知识点
用Vue实现状态列表的操作涵盖所有的知识点
- python字符串,列表常用操作
24天养成一个好习惯,第五天! 一.字符串需要掌握的操作 1.取值(索引取值)需要注意的是只能取,不能改 msg = 'hello world' print(msg[4]) 2.切片(顾头不顾尾) m ...
随机推荐
- Linux性能优化从入门到实战:02 CPU篇:平均负载
每次发现系统变慢时,我们通常做的第一件事,就是执行 top 或 uptime 命令: $ uptime 22:22:17 up 2 days, 20:14, 1 user, load average: ...
- python基础模块,包
#import cal,time #导入模块名可以看作导入一个变量 #from cal import add # from cal import *#引入所有变量 *代表所有 占内存 不推荐 # # ...
- frugally-deep: Header-only library for using Keras models in C++
// Convenience wrapper around predict for models with // single tensor outputs of shape (1, 1, 1), / ...
- 【leetcode】816. Ambiguous Coordinates
题目如下: 解题思路:我的方案是先把S拆分成整数对,例如S='1230',先拆分成(1,230),(12,30),(123,0),然后再对前面整数对进行加小数点处理.比如(12,30)中的12可以加上 ...
- [CF-GYM]Abu Tahun Mod problem题解
前言 这道题比较简单,但我还是想了好一会 题意简述 Abu Tahun很喜欢回文. 一个数组若是回文的,那么它从前往后读和从后往前读都是一样的,比如数组\(\left\{1\right\},\left ...
- jquery ajax请求回调
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- RabbitMQ生产者消费者模型构建(三)
ConnectionFactory:获取连接(地址,端口号,用户名,密码,虚拟主机等) Connection:一个连接 Channel:数据通信信道,可发送.接收消息 Queue:具体的消息存储队列 ...
- [CSP-S模拟测试]:Walk(树的直径+数学)
题目描述 给定一棵$n$个节点的树,每条边的长度为$1$,同时有一个权值$w$.定义一条路径的权值为路径上所有边的权值的最大公约数.现在对于任意$i\in [1,n]$,求树上所有长度为$i$的简单路 ...
- 【数据库】一篇文章搞掂:Oracle数据库
PL/SQL的使用 1.安装使用 1.1.安装暂略 1.2.使用 添加环境变量 打开PL/SQL,不要登录,进入界面后,打开设置Preference 设置主目录和OCI库
- EZOJ #373排序
分析 它居然真的是个nlog^3暴力?! 两个数在加小于min(lowbit(x),lowbit(y))的数时对他们的奇偶性不影响 因此每次加上min(lowbit(x),lowbit(y))判断此时 ...