當(dāng)前位置:
首頁(yè) >
Springboot整合freemarker和相应的语法
發(fā)布時(shí)間:2025/4/16
47
豆豆
生活随笔
收集整理的這篇文章主要介紹了
Springboot整合freemarker和相应的语法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
FreeMarker 是?款 模板引擎: 即?種基于模板和要改變的數(shù)據(jù), 并?來(lái)?成輸出?本(HTML??,?郵件,配置?件,源代碼等)的通??具。 是?個(gè)Java類(lèi)庫(kù)。
FreeMarker 被設(shè)計(jì)?來(lái)?成 HTML Web ??,特別是基于 MVC 模式的應(yīng)?程序,將視圖從業(yè)務(wù)邏輯抽離處理,業(yè)務(wù)中不再包括視圖的展示,?是將視圖交給 FreeMarker 來(lái)輸出。雖然 FreeMarker 具有些編程的能?,但通常由 Java 程序準(zhǔn)備要顯示的數(shù)據(jù),由 FreeMarker ?成??,通過(guò)模板顯示準(zhǔn)備數(shù)據(jù)。
FreeMarker是一款Spring官方推薦使用的模板引擎。以’.flt’結(jié)尾的文件。
FreeMarker環(huán)境搭建(SpringBoot集成FreeMarker)
1.新建SpringBoot Web項(xiàng)?
2.配置坐標(biāo)依賴(lài)和部署插件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.xxxx</groupId><artifactId>054-springboot-freemarker</artifactId><version>0.0.1-SNAPSHOT</version><name>054-springboot-freemarker</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><spring-boot.version>2.3.7.RELEASE</spring-boot.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency><!-- freemarker的坐標(biāo)依賴(lài) --><dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.23</version></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.3.7.RELEASE</version><configuration><mainClass>com.xxxx.Application</mainClass></configuration><executions><execution><id>repackage</id><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>3.修改配置?件 application.yml
## freemarker freemarker:#處理所有以.ftl結(jié)尾的文件;ftl是freemarker默認(rèn)的文件后綴suffix: .ftlcontent-type: text/html#設(shè)置模板的默認(rèn)編碼:UTF-8charset: UTF-8#默認(rèn)從設(shè)置的目錄下開(kāi)始查找對(duì)應(yīng)的模板文件template-loader-path: classpath:/views/4.編寫(xiě)Controller類(lèi)
總結(jié)
以上是生活随笔為你收集整理的Springboot整合freemarker和相应的语法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Spring常见注解
- 下一篇: Day4-Springmvc表单数据