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# 配置#thymeleafspring.thymeleaf.cache=falsespring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.check-template-location=truespring.thymeleaf.suffix=.htmlspring.thymeleaf.encoding=UTF-8spring.thymeleaf.servlet.content-type=text/htmlspring.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 * 文件說明: */@Controllerpublic 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)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 詳解Android studio 動(dòng)態(tài)fragment的用法2. 什么是python的自省3. 解決Android studio xml界面無法預(yù)覽問題4. Spring Boot和Thymeleaf整合結(jié)合JPA實(shí)現(xiàn)分頁(yè)效果(實(shí)例代碼)5. 圖文詳解vue中proto文件的函數(shù)調(diào)用6. php模擬實(shí)現(xiàn)斗地主發(fā)牌7. Springboot Druid 自定義加密數(shù)據(jù)庫(kù)密碼的幾種方案8. Vue封裝一個(gè)TodoList的案例與瀏覽器本地緩存的應(yīng)用實(shí)現(xiàn)9. vue 使用localstorage實(shí)現(xiàn)面包屑的操作10. Vuex localStorage的具體使用

網(wǎng)公網(wǎng)安備