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

