1、创建maven项目,添加pom依赖

<!--springboot项目依赖的父项目-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent> <dependencies>
<!--注入springboot启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <!--注入springboot对freemarker视图技术的支持-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>

2、创建controller

package com.bjsxt.controller;

import com.bjsxt.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import java.util.ArrayList;
import java.util.List; /**
* Created by Administrator on 2019/2/6.
*/
@Controller
public class UserController { @RequestMapping("/toUserList")
public String toUserList(Model model){
List<User> userList=new ArrayList<User>();
userList.add(new User(1L,"张三","男"));
userList.add(new User(2L,"李四","女"));
userList.add(new User(3L,"王五","男"));
model.addAttribute("userList",userList);
return "user_list";
}
}

3、创建freemarker模版文件user_list.ftl

注意:springboot 要求模板形式的视图层技术的文件必须要放到 src/main/resources 目录下必
须要一个名称为 templates

<html>
<head>
<title>用户列表</title>
</head>
<body> <table border="1px solid red">
<tr>
<th>id</th>
<th>姓名</th>
<th>性别</th>
</tr>
<#list userList as user>
<tr>
<td>${user.id}</td>
<td>${user.name}</td>
<td>${user.sex}</td>
</tr>
</#list>
</table>
</body>
</html>

4、创建启动器

package com.bjsxt;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
* Created by Administrator on 2019/2/6.
*/
@SpringBootApplication
public class App { public static void main(String[] args){
SpringApplication.run(App.class,args);
}
}

目录结构

SpringBoot: 8.整合freemarker(转)的更多相关文章

  1. springboot整合freemarker

    前后端分离现在越来越多,如何有效的使用springboot来整合我们的页面是一个很重要的问题. springboot整合freemarker有以下几个步骤,也总结下我所犯的错误: 1.加依赖: 2.配 ...

  2. springboot 整合 freemarker

    springboot 整合 freemarker 依赖 <parent> <groupId>org.springframework.boot</groupId> & ...

  3. SpringBoot整合freemarker 引用基础

    原 ElasticSearch学习笔记Ⅲ - SpringBoot整合ES 新建一个SpringBoot项目.添加es的maven坐标如下: <dependency> <groupI ...

  4. springboot学习入门简易版四---springboot2.0静态资源访问及整合freemarker视图层

    2.4.4 SpringBoot静态资源访问(9) Springboot默认提供静态资源目录位置需放在classpath下,目录名需要符合如下规则 /static  /public  /resourc ...

  5. 【SpringBoot】09.SpringBoot整合Freemarker

    SpringBoot整合Freemarker 1.修改pom文件,添加坐标freemarker启动器坐标 <project xmlns="http://maven.apache.org ...

  6. 玩转 SpringBoot 2 快速整合 | FreeMarker篇

    FreeMarker 介绍 Apache FreeMarker™是一个模板引擎:一个Java库,用于根据模板和更改数据生成文本输出(HTML网页,电子邮件,配置文件,源代码等).模板是用FreeMar ...

  7. spring boot 整合freemarker(好用!!!!)

    springboot整合freemarker 1.pom依赖 <!-- 引入freeMarker的依赖包. --> <dependency> <groupId>or ...

  8. SpringBoot基础及FreeMarker模板

    案例springboot_freemarker application.properties配置文件 ###FreeMarker配置 spring.freemarker.template-loader ...

  9. 整合Freemarker视图层和整合jsp视图层和全局捕获异常

    SpringBoot静态资源访问 1.静态资源:访问 js / css /图片,传统web工程,webapps springboot 要求:静态资源存放在resource目录下(可以自定义文件存放) ...

  10. SpringBoot下配置FreeMarker配置远程模版

    需求产生原因 要求在同一个接口中,根据不同的参数,返回不同的视图结果 所有的视图中的数据基本一致 要求页面能静态化,优化SEO 例如:A接口返回客户的信息 客户A在调用接口时,返回其个性化定制的页面A ...

随机推荐

  1. C#实现异步阻塞TCP(SocketAsyncEventArgs,SendAsync,ReceiveAsync,AcceptAsync,ConnectAsync)

    1.类 (1)socket IO操作内存管理类 BufferManager // This class creates a single large buffer which can be divid ...

  2. HashMap源码分析一

           HashMap在java编程中,算使用频率top10中的类了.这里是关于HashMap的源码的分析.一个类的源码分析,要看他的来龙去脉,他的历史迭代.一来从以前的版本开始分析,由易到难: ...

  3. Java数据库小项目02--管家婆项目

    目录 项目要求 开发环境搭建 工具类JDBCUtils 创建管家婆数据表 项目分层 MainApp层 MainView层 ZhangWuController层 ZhangWuService层 Zhan ...

  4. Java基础知识学习01

    0 项目,包,文件,类 Mytest是自己建的java工程,包含src和JRE System Libery.其中src是存放自己的代码的地方,JRE包含程序运行时所需要的各种文件:在src下包含Tes ...

  5. react-native-page-scrollview 的使用方法(实现酷炫的分页轮播效果,还支持自定义View)

    react-native-page-scrollview 对ScrollView的封装,可以很方便的实现水平,垂直分页轮播效果.而且可以自定义分页宽高,和侧边View的旋转,透明度,大小等. 对于原生 ...

  6. LinkedBlockingQueue 实现 生产者 消费者

    转载:https://blog.csdn.net/sinat_36553913/article/details/79533606 Java中使用LinkedBlockingQueue实现生产者,消费者 ...

  7. Noip2016 提高组 Day1

    T1 玩具迷题 直通 思路: 1.首先根据数据范围来看,储存小人的姓名开一个二维char数组即可(不会开爆) 2.然后看他给出的样例以及条件什么的,能够确定出 ①朝内向右,朝外向左均为+ ②朝内向左, ...

  8. SQLAlchemy框架

    Python 的 ORM 框架 SQLAlchemy 有些同学已经听说过这个框架的大名了,也听说了 SQLAlchemy 没有 Django 的 Models 好用 我在这里官宣辟谣一下啊, Mode ...

  9. 【APUE】第3章 文件I/O (3) 文件共享、原子操作、函数dup/dup2、函数sync/fsync/fdatasync、函数fcntl、函数ioct1、目录/dev/fd 使用说明

    1.文件共享 UNIX系统支持在不同的进程间共享打开文件.为了说明这种共享,以下介绍内核用于所有I/O的数据结构. 内核使用3种数据结构表示打开文件,它们之间的关系决定了在文件共享方面一个进程对另一个 ...

  10. ANDROID_ID

    在设备首次启动时,系统会随机生成一个64位的数字,并把这个数字以16进制字符串的形式保存下来,这个16进制的字符串就是ANDROID_ID,当设备被wipe后该值会被重置.可以通过下面的方法获取: i ...