boot-集成freemarker

本文详细介绍了如何在SpringBoot项目中集成Freemarker模板引擎,包括添加依赖、配置属性、创建视图模板等步骤,帮助开发者快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

boot-集成freemarker

首先加入freemarker依赖 到pom.xml

   <dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-freemarker</artifactId>
   </dependency>

application.properties加入配置信息


##视图解析器
##jsp 视图解析器配置
#spring.mvc.view.prefix=/
#spring.mvc.view.suffix=.jsp

##增加freemarker的视图解析器

## 首先要配置模板文件的位置

spring.freemarker.template-loader-path=classpath:/templates/page/
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.request-context-attribute=request
spring.freemarker.suffix=.ftl

##数据库的连接信息
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/1609a?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT
spring.datasource.username=root
spring.datasource.password=ghw

##mybatis简写
mybatis.type-aliases-package=com.bw.entity

在templates目录下创建个page文件夹 创建list.ftl

		<html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<!-- 使用freemrker 完成列表的展示 -->
<h6>freemrker 完成列表的展示 </h>
<table>
	<tr>
		<td>日程编号123</td>
		<td>日程名称</td>
		<td>日程日期</td>
		<td>日程时间</td>
		<td>
			<a href="toAdd" >增加</a>
		</td>
	</tr>
	
	<!-- 使用list标签 遍历list集合 -->
	<#list list as rc>
	<tr>
		<td>${rc.sid }</td>
		<td>${rc.sname }</td>
		<td>${rc.riqi }</td>
		<td>${rc.shijian }</td>
	</tr>
	</#list>

</table>

</body>
</html>

页面使用list循环

<#list list as rc>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值