SpringBoot使用Thymeleaf模板引擎訪問靜態(tài)html的過程
最近要做一個java web項目,因為頁面不是很多,所以就沒有前后端分離,前后端寫在一起,這時候就用到thymeleaf了,以下是不動腦式的傻瓜教程。。。。。
一:創(chuàng)建spring boot的web項目,過程略;
二:依賴如下:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>2.1.2.RELEASE</version> </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>
三:配置文件:application.properties
#端口號 server.port=8099 # 配置 #thymeleaf spring.thymeleaf.cache=false spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.check-template-location=true spring.thymeleaf.suffix=.html spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.servlet.content-type=text/html spring.thymeleaf.mode=HTML
四:項目的templates文件夾下新建頁面success.html,如下
五:controller
import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; /** * @author liuhongyang * @2020/10/20 14:35 * 文件說明: */ @Controller public class FirstTestController { @RequestMapping(value = "hello") public String hello(ModelMap modelMap) { modelMap.put("hei", "thymeleaf"); return "success"; } }
六:訪問如下,完成
到此這篇關(guān)于SpringBoot使用Thymeleaf模板引擎訪問靜態(tài)html的過程的文章就介紹到這了,更多相關(guān)SpringBoot Thymeleaf模板訪問靜態(tài)html內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- springboot學(xué)習(xí)之Thymeleaf模板引擎及原理介紹
- springboot?使用clickhouse實時大數(shù)據(jù)分析引擎(使用方式)
- SpringBoot整合Drools規(guī)則引擎動態(tài)生成業(yè)務(wù)規(guī)則的實現(xiàn)
- springboot2.5.2與 flowable6.6.0整合流程引擎應(yīng)用分析
- SpringBoot2整合Drools規(guī)則引擎及案例詳解
- 詳解Elastic Search搜索引擎在SpringBoot中的實踐
- 詳解SpringBoot+Thymeleaf 基于HTML5的現(xiàn)代模板引擎
- springboot?整合表達(dá)式計算引擎?Aviator?使用示例詳解
相關(guān)文章
Java的JSON格式轉(zhuǎn)換庫GSON的初步使用筆記
GSON是Google開發(fā)并在在GitHub上開源的Java對象與JSON互轉(zhuǎn)功能類庫,在Android開發(fā)者中也大受歡迎,這里我們就來看一下Java的JSON格式轉(zhuǎn)換庫GSON的初步使用筆記:2016-06-06Java9新特性Stream流API優(yōu)化與增強(qiáng)
這篇文章主要為大家介紹了Java9新特性Stream流API優(yōu)化與增強(qiáng)的用法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助祝大家多多進(jìn)步,早日升職加薪2022-03-03SpringCloud超詳細(xì)講解負(fù)載均衡組件Ribbon源碼
在微服務(wù)中,對服務(wù)進(jìn)行拆分之后,必然會帶來微服務(wù)之間的通信需求,而每個微服務(wù)為了保證高可用性,又會去部署集群,那么面對一個集群微服務(wù)進(jìn)行通信的時候,如何進(jìn)行負(fù)載均衡也是必然需要考慮的問題2022-07-07Java中的PrintWriter 介紹_動力節(jié)點Java學(xué)院整理
PrintWriter 是字符類型的打印輸出流,它繼承于Writer。接下來通過本文給大家介紹java中的 PrintWriter 相關(guān)知識,感興趣的朋友一起學(xué)習(xí)吧2017-05-05Java實現(xiàn)超大Excel文件解析(XSSF,SXSSF,easyExcel)
這篇文章主要為大家詳細(xì)介紹了如何利用Java語言實現(xiàn)超大Excel文件解析(XSSF,SXSSF,easyExcel)以及速度的對比,感興趣的可以了解一下2022-07-07SpringBoot深入探究四種靜態(tài)資源訪問的方式
這一節(jié)詳細(xì)的學(xué)習(xí)一下SpringBoot的靜態(tài)資源訪問相關(guān)的知識點。像這樣的知識點還挺多,比如SpringBoot2的Junit單元測試等等。本章我們來了解靜態(tài)資源訪問的四種方式2022-05-05