fremarker 基础
springboot 基础配置
server:
port: 8088 #服务端口
servlet:
context-path: /test-freemarker
spring:
application:
name: test-freemarker #指定服务名
freemarker:
request-context-attribute: rc #把Spring的RequestContext对象暴露为变量rc
expose-request-attributes: true # 模板能够使用request请求参数
expose-session-attributes: true # 模板能够使用 session 参数
charset: UTF-8
content-type: text/html
suffix: .ftl # 解析文件后缀,也可以为 html
enabled: true
template-loader-path: classpath:/templates/ # 模板解析目录,默认
resources:
add-mappings: false #关闭工程中默认的资源处理
mvc:
throw-exception-if-no-handler-found: true #出现错误时直接抛出异常
常见的request、session、context 获取属性值的
url请求参数值:${RequestParameters['param1']!""}<br/>
Request属性值 : ${Request['attr1']}<br/>
Session属性值 : ${Session['session1']}<br/>
contextPath: ${rc.contextPath}<br/>
请求地址: ${rc.requestUri}