springboot整合freemarker
2021-06-16 19:05
标签:tin 1.0 mode 属性 后缀 src stc marker rip 项目整体路径 1、配置pom.xml,引入freemarker依赖 2、配置freemarker模板属性 3、编写后台代码 springboot整合freemarker 标签:tin 1.0 mode 属性 后缀 src stc marker rip 原文地址:https://www.cnblogs.com/it-noob/p/9723683.html
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-freemarkerartifactId>
dependency>
# freemarker
spring.freemarker.allow-request-override=false
spring.freemarker.allow-session-override=false
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.enabled=true
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=true
spring.freemarker.prefer-file-system-access=true
# 这是重点, 会过滤.ftl后缀的文件
spring.freemarker.suffix=.ftl
# spring boot 默认的页面模板存放目录
spring.freemarker.template-loader-path=classpath:/templates/
spring.freemarker.settings.template_update_delay=0
spring.freemarker.settings.default_encoding=UTF-8
spring.freemarker.settings.classic_compatible=true
spring.freemarker.order=1
/**
* Copyright (C), 2017-2018, XXX有限公司
* FileName: testController
* Author: 丶Zh1Guo
* Date: 2018/9/29 14:40
* Description: 测试
* History:
* */
package com.wzg.freemarker.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Date;
/**
* 〈一句话功能简述〉
* 〈测试〉
*
* @author 丶Zh1Guo
* @create 2018/9/29
* @since 1.0.0
*/
@Controller
public class testController {
@RequestMapping(value = "/hello")
public String demo(Model model) {
model.addAttribute("name", "鬼谷子");
model.addAttribute("age", "25");
model.addAttribute("sex", "man");
model.addAttribute("birth", new Date());
return "hello";
}
}
4、编辑ftl页面DOCTYPE html>
html lang="en">
head>title>SpringBoot + Freemarkertitle>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
head>
body>
Hello ${name}${age}${sex}
p>${birth?string("yyyy-MM-dd HH:mm:ss.sss")}p>
body>
html>5、访问