博客
关于我
6、SpringBoot2.0与Freemarker整合(六)
阅读量:353 次
发布时间:2019-03-04

本文共 1623 字,大约阅读时间需要 5 分钟。

1、引入相关的依赖:

org.springframework.boot
spring-boot-starter-freemarker

2、在resources目录下的templates目录下创建fkHtml.ftl文件,然后添加如下内容:

    
Title

首页

1、访问pojo中的属性: ${user.name}- ${user.age}
2、遍历集合中的数据并取循环中的下标:
<#list userList as user> ${user!}: ${user_index}、
3、判断语句:
<#list userList as user> <#if user_index % 2 == 0> red、 <#else> blue、
4、日期类型格式化
${date?date}
<#--${date?time}
--> ${date?datetime}
5、Null值的处理
如果直接取一个不存在的变量时会报异常
${aaaa!}可以默认将aaaa设置为空字符串

3、编写freemarker测试类FKController,然后添加以下代码用于测试:

@RestControllerpublic class FKController {    @RequestMapping("/fk")    public ModelAndView fkHtml(ModelAndView modelAndView){        modelAndView.setViewName("fkHtml");        ArrayList
list = new ArrayList<>(); list.add("admin"); list.add("user1"); list.add("user2"); User user = new User(); user.setId(18); user.setName("李现"); user.setAge(18); Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String dateTime = format.format(date); modelAndView.addObject("date",dateTime); modelAndView.addObject("userList",list); modelAndView.addObject("user",user); return modelAndView; }}

4、然后浏览器中输入如下网址用于测试:

http://localhost:8081/fk

转载地址:http://isse.baihongyu.com/

你可能感兴趣的文章
Netty源码—3.Reactor线程模型三
查看>>
Netty源码—3.Reactor线程模型四
查看>>
Netty源码—4.客户端接入流程一
查看>>
Netty源码—4.客户端接入流程二
查看>>
Netty源码—5.Pipeline和Handler一
查看>>
Netty源码—5.Pipeline和Handler二
查看>>
Netty源码—6.ByteBuf原理一
查看>>
Netty源码—6.ByteBuf原理二
查看>>
Netty源码—7.ByteBuf原理三
查看>>
Netty源码—7.ByteBuf原理四
查看>>
Netty源码—8.编解码原理一
查看>>
Netty源码—8.编解码原理二
查看>>
Netty源码解读
查看>>
netty的HelloWorld演示
查看>>
Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
查看>>
Netty的网络框架差点让我一夜秃头,哭了
查看>>
Netty相关
查看>>
Netty简介
查看>>
Netty线程模型理解
查看>>
netty解决tcp粘包和拆包问题
查看>>