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:springboot整合freemarker的更多相关文章

  1. SpringBoot学习- 4、整合JWT

    SpringBoot学习足迹 1.Json web token(JWT)是为了网络应用环境间传递声明而执行的一种基于JSON的开发标准(RFC 7519),该token被设计为紧凑且安全的,特别适用于 ...

  2. SpringBoot学习- 3、整合MyBatis

    SpringBoot学习足迹 1.下载安装一个Mysql数据库及管理工具,同类工具很多,随便找一个都可以,我在windows下做测试项目习惯使用的是haosql 它内部集成了MySql-Front管理 ...

  3. SpringBoot学习- 5、整合Redis

    SpringBoot学习足迹 SpringBoot项目中访问Redis主要有两种方式:JedisPool和RedisTemplate,本文使用JedisPool 1.pom.xml添加dependen ...

  4. SpringBoot学习- 8、整合Shiro

    SpringBoot学习足迹 Shiro是什么,引自百度百科:Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理.使用Shiro的易于理解的API,您可以快 ...

  5. springboot学习笔记-4 整合Druid数据源和使用@Cache简化redis配置

    一.整合Druid数据源 Druid是一个关系型数据库连接池,是阿里巴巴的一个开源项目,Druid在监控,可扩展性,稳定性和性能方面具有比较明显的优势.通过Druid提供的监控功能,可以实时观察数据库 ...

  6. springboot学习笔记-3 整合redis&mongodb

    一.整合redis 1.1 建立实体类 @Entity @Table(name="user") public class User implements Serializable ...

  7. springboot学习四:整合mybatis

    在application.properties加入配置 ## Mybatis 配置 mybatis.typeAliasesPackage=org.spring.springboot.domain my ...

  8. springboot学习三:整合jsp

    在pom.xml加入jstl <!--springboot tomcat jsp 支持开启--> <dependency> <groupId>org.apache. ...

  9. SpringBoot(三)-- 整合FreeMarker模板

    1.pom依赖 <!-- 引入freeMarker的依赖包. --> <dependency> <groupId>org.springframework.boot& ...

  10. SpringBoot学习(一):SpringBoot入门

    1.Spring Boot 简介 1) 简化Spring应用开发的一个框架: 2) 整个Spring技术栈的一个大整合: 3) J2EE开发的一站式解决方案: 2.微服务 2014,martin fo ...

随机推荐

  1. maya2014无法安装卸载激活失败

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  2. mybatis连接mysql数据库实现的jdbc功能

    最近公司项目要使用myBatis,自己以前没有接触过,就在网上找到了一些资料研究了些.初步做出了基于myBatis连接mysql数据库的jdbc实现的功能. employee.java package ...

  3. httpd.conf 配置

    # # This is the main Apache server configuration file. It contains the # configuration directives th ...

  4. 关于“importer.GetNPOTScale() == TextureImporter::kNPOTKeep”问题的简单处理方法

    在运行NGUI打包图集的时候碰到下图所示的错误,这个错误导致图片无法正确的规格进行图集生成.结果是图片变成各种诡异的尺寸!! 通过关键字搜索,发现国外有讨论这个问题的解决方案: 将图片转换为textu ...

  5. C#图表控件ZedGraph使用

    最近从java转到C#下开发PC端的桌面程序,之前也尝试用java GUI写桌面程序,发现java写桌面程序还是诸多不便变,虽然最后也写出来了,但是决心还是另起平台,有了一定的java基础,来学习C# ...

  6. Java对象转换成Json字符串是无法获得对应字段名

    问题: 代码中已经标注 @JSONField(name = "attrs") private String abc; public String getA() { return a ...

  7. Eclipse常用设置和快捷键

    1.提示键配置一般默认情况下,Eclipse ,MyEclipse 的代码提示功能是比Microsoft Visual Studio的差很多的,主要是Eclipse ,MyEclipse本身有很多选项 ...

  8. Android GreenDAO 3.0 不修改版本号的情况下增加、删除表、添加字段

    最近项目中使用了GreenDAO的3.0以上的版本,出现需要增加删除表的需求,刚开始用,发现官方对增加和删除的方法是每次去修改数据库版本号,版本一旦升级,那么原来数据库中的表会全部删除再重建.太麻烦, ...

  9. Android 极光推送JPush---自定义提示音

    极光推送提供三种方法实现Notification通知 三方开发平台发送普通消息,客户端设置PushNotificationBuilder,实现基础的Notification通知 三方开放平台发送普通消 ...

  10. iOS 谓词(NSPredicate)的应用

    Cocoa中谓词(Predicate)提供了一个通用的查询方式处理数据,可以获取和指定数据的过滤形式,Cocoa实际开发中可以是使用NSPredicate及其父类NSComparisonPredica ...