spring-boot集成freemarker

1.spring-boot集成freemarker需要添加freemarker启动器依赖

            <!-- freemarker的启动器 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-freemarker</artifactId>
		</dependency>

2.写freemarker页面推荐使用第三方编辑软件 HBuilder

HBuilder选择项目文件夹的根目录打开!

要在resource目录下创建一个文件夹,目录结构如下所示!!!  templates目录不能被直接访问的,框架做了限制

3.编写模板文件

模板文件的路径与controller返回的字符串对应

模板文件就直接写一个了

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>freemarker模板文件的扩展名是ftl</title>
</head>
<body>

	<table border="1" align="center" width="50%">
		<tr>
			<th>序号</th>
			<th>姓名</th>
			<th>年龄</th>
		</tr>
		<#list userList as user>
				<tr>
					<td>${user.id}</td>
					<td>${user.name}</td>
					<td>${user.age}</td>
				</tr>
		</#list>
	</table>
	

</body>
</html>

 

4.启动器,最简单的启动器,不需要配置什么。