# springboot-base-three **Repository Path**: springbook_foundation/springboot-base-three ## Basic Information - **Project Name**: springboot-base-three - **Description**: springboot集成freemarker - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2019-05-24 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## [freemarke在线文档](http://freemarker.foofun.cn/index.html) ## [本项目地址](https://gitee.com/springbook_foundation/springboot-base-three) ### FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页、电子邮件、配置文件、源代码等)的通用工具。 它不是面向最终用户的,而是一个Java类库,是一款程序员可以嵌入他们所开发产品的组件 ### 基础maven包 1. spring-boot-starter-parent springboot 启动父包 2. spring-boot-starter-web 开启web服务 3. spring-boot-starter-test 测试类包 4. spring-boot-maven-plugin plugin插件 能够将Spring Boot应用打包为可执行的jar或war文件 5. spring-boot-starter-freemarker freemarker模板引擎开发包 ### springBoot项目 目录结构 ``` │ pom.xml └─src └─main ├─java │ └─com │ └─base │ │ Application.java ## 启动类,启动类不能直接在java目录下 │ │ │ ├─config │ │ WebMvcConfig.java ## springbootmvc配置类 │ │ │ └─controller │ IndexController.java │ └─resources │ application.yml ## springboot配置文件 │ ├─static ## 静态资源目录(js,css,image) └─templates ## freemarker 模板存放目录 index.ftl ``` ### pom.xml 配置如下 ``` 4.0.0 springboot-base springboot-base-three 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent 1.5.10.RELEASE 1.8 UTF-8 -server -Xms64m -Xmx256m -XX:PermSize=64m -XX:MaxPermSize=128m -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true aliyun-releases http://maven.aliyun.com/nexus/content/groups/public aliyun-repos http://maven.aliyun.com/nexus/content/groups/public org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-freemarker org.springframework.boot spring-boot-maven-plugin ``` ### application.yml 配置如下 ```bash spring: application: # 服务名 name: base #freemarker配置 freemarker: cache: false # 字符集 charset: UTF-8 # 检查模板位置 check-template-location: true # 模板内容类型 content-type: text/html expose-request-attributes: true expose-session-attributes: true request-context-attribute: request # 模板位置 template-loader-path: classpath:/templates server: # 服务端口 port: 8003 ``` ### 模板表达式示例 index.ftl ```

字符串属性

${userName!""}

日期属性

${(date?string('yyyy-MM-dd hh:mm:ss'))!'日期为null'}

循环

<#list list as item>

第${item_index+1}个用户

用户名:${item.name}

id:${item.id}

判断1

<#if userName =='刘志强'>

存在刘志强

<#elseif userName =='王妍'>

存在王妍

<#else>

不存在刘志强和王妍

判断2

<#assign foo = (userName =='王妍')> ${foo?then('存在王妍', '不存在王妍')} ```