2018-03-13
springboot-集成freemarker
springboot 评论:0 浏览:81

转载请注明出处:https://oldnoop.tech/c/169.html

引入依赖

创建工程的时候添加freemarker模块

或者在pom.xml中添加如下依赖

配置

#配置freemarker视图解析器
#编码
spring.freemarker.charset=UTF-8
#视图页面中(RequestContext的变量名)
spring.freemarker.request-context-attribute=request
#设置freemarker视图文件存放的目录
spring.freemarker.prefix=/ftl/
#设置freemarker视图文件的后缀
spring.freemarker.suffix=.html
#spring.freemarker.enabled=true
#spring.freemarker.template-loader-path=classpath:/templates/
spring.freemarker.allow-request-override=false
spring.freemarker.allow-session-override=false
spring.freemarker.cache=false
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.expose-spring-macro-helpers=true
spring.freemarker.prefer-file-system-access=true

在src/main/resources的templates文件夹下创建ftl的文件夹
存放freemarker的视图模板文件

freemarker文件中获取上下文路径

在application.properties中配置RequestContext的变量名

spring.freemarker.request-context-attribute=request

然后在页面中定义上下文路径的变量

<#assign ctx="${request.contextPath}">   

然后就可以在页面填写路径的时候, 使用 ${ctx}



  • 转载请注明出处:https://oldnoop.tech/c/169.html

Copyright © 2018 oldnoop.tech. All Rights Reserved

鄂ICP备2023022735号-1