欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 前端技术 > javascript >内容正文

javascript

Spring Boot 13 之freemarker

发布时间:2025/5/22 javascript 120 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Spring Boot 13 之freemarker 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

2019独角兽企业重金招聘Python工程师标准>>>

1、加入依赖

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-freemarker</artifactId>

</dependency>

2、在application.properties下加入配置

spring.freemarker.allow-request-override=false

spring.freemarker.cache=true

spring.freemarker.check-template-location=true

spring.freemarker.charset=UTF-8

spring.freemarker.content-type=text/html

spring.freemarker.expose-request-attributes=false

spring.freemarker.expose-session-attributes=false

spring.freemarker.expose-spring-macro-helpers=false

3、编写controller

/**

* 返回模板.

*/

@RequestMapping("/helloFtl")

public String helloFtl(Map<String,Object> map){

map.put("hello","from TemplateController.helloFtl");

return"/helloFtl";

}

4、在 src/main/resources/templates下加入模板。

src/main/resouces/templates/helloFtl.ftl

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"

xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">

<head>

<title>Hello World!</title>

</head>

<body>

<h1>Hello.v.2</h1>

<p>${hello}</p>

</body>

</html>

转载于:https://my.oschina.net/huaForever/blog/807165

总结

以上是生活随笔为你收集整理的Spring Boot 13 之freemarker的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。