【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 ...
随机推荐
- OGG复制进程延迟不断增长
1.注意通过进程查找sql_id时,进程号要查询两次 2.杀进程的连接 https://www.cnblogs.com/kerrycode/p/4034231.html 参考资料 1.https:// ...
- leetcode 实现-168.Excel表列名称
168.Excel表列名称 描述 给定一个正整数,返回它在 Excel 表中相对应的列名称. 例如, 1 -> A 2 -> B 3 -> C … 26 -> Z 27 -&g ...
- 怎样group by一列 select多列
之前sql用的少 竟然不知道这个小技巧 1 将要查询的列 添加到group by后面(会影响查询结果) 2 使用聚合函数如 max select a.accounttitlecode, max(b.c ...
- Python日志库logging总结
转自 https://cloud.tencent.com/developer/article/1354396 在部署项目时,不可能直接将所有的信息都输出到控制台中,我们可以将这些信息记录到日志文件中 ...
- 移动端触摸、点击事件优化(fastclick源码学习)
移动端触摸.点击事件优化(fastclick源码学习) 最近在做一些微信移动端的页面,在此记录关于移动端触摸和点击事件的学习优化过程,主要内容围绕fastclick展开.fastclick githu ...
- Python3解leetcode Path Sum III
问题描述: You are given a binary tree in which each node contains an integer value. Find the number of p ...
- 【Java】Java调用第三方接口
Get请求与Http请求 https://www.w3school.com.cn/tags/html_ref_httpmethods.asp HttpClient HTTP 协议可能是现在 Inter ...
- 20180826(02)-Java集合框架
Java 集合框架 早在Java 2中之前,Java就提供了特设类.比如:Dictionary, Vector, Stack, 和Properties这些类用来存储和操作对象组. 虽然这些类都非常有用 ...
- 谈谈vue双向数据绑定问题
vue是MVVM模型,vueObserver 数据监听器,把一个普通的 JavaScript 对象传给 Vue 实例的 data 选项,Vue 将遍历此对象所有的属性,并使用Object.define ...
- 阿里云code下载代码和更新代码
1- 本地新建一个文件夹,进入文件夹下面右击打开git 2- Git init初始化一个.git文件夹 3- Git clone git@code.aliyun.com:username/space- ...