前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring Boot 集成 Freemarker

Spring Boot 集成 Freemarker

作者头像
北漂的我
发布2019-05-29 10:50:08
5080
发布2019-05-29 10:50:08
举报
文章被收录于专栏:北漂的我北漂的我

1. pom.xml 文件里添加 Freemarker starter 依赖

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

2. application.properties 文件中添加 Freemarker 相关配置

#设置ftl文件路径
spring.freemarker.template-loader-path=classpath:/templates
#关闭缓存,即时刷新,生产环境应改为true
spring.freemarker.cache=false
#设置ftl编码格式
spring.freemarker.charset=UTF-8
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html; charset=utf-8
spring.freemarker.expose-request-attributes=true
spring.freemarker.expose-session-attributes=true
spring.freemarker.request-context-attribute=request
spring.freemarker.suffix=.ftl

3. java代码示例

package com.codingos.springbootdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.codingos.springbootdemo.entity.Resource;

@Controller
@RequestMapping("/ftl")
public class FreemarkerController {

	@Autowired
	private Resource resource;
	
	@RequestMapping("/index")
	public String index(Model model) {
		model.addAttribute("resource", resource);
		return "freemarker/index";
	}
	
	@RequestMapping("/center")
	public String center() {
		return "freemarker/center/center";
	}
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档