博客
关于我
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应用实例
查看>>
netty底层——nio知识点 ByteBuffer+Channel+Selector
查看>>
netty底层源码探究:启动流程;EventLoop中的selector、线程、任务队列;监听处理accept、read事件流程;
查看>>
Netty心跳检测
查看>>
Netty心跳检测机制
查看>>
netty既做服务端又做客户端_网易新闻客户端广告怎么做
查看>>
netty时间轮
查看>>
Netty服务端option配置SO_REUSEADDR
查看>>
Netty核心模块组件
查看>>
Netty框架内的宝藏:ByteBuf
查看>>
Netty框架的服务端开发中创建EventLoopGroup对象时线程数量源码解析
查看>>
Netty源码—1.服务端启动流程一
查看>>
Netty源码—1.服务端启动流程二
查看>>
Netty源码—2.Reactor线程模型一
查看>>
Netty源码—2.Reactor线程模型二
查看>>
Netty源码—3.Reactor线程模型三
查看>>
Netty源码—3.Reactor线程模型四
查看>>
Netty源码—4.客户端接入流程一
查看>>
Netty源码—4.客户端接入流程二
查看>>
Netty源码—5.Pipeline和Handler一
查看>>