SpringBoot使用Thymeleaf模板引擎訪問(wèn)靜態(tài)html的過(guò)程
最近要做一個(gè)java web項(xiàng)目,因?yàn)轫?yè)面不是很多,所以就沒(méi)有前后端分離,前后端寫在一起,這時(shí)候就用到thymeleaf了,以下是不動(dòng)腦式的傻瓜教程。。。。。
一:創(chuàng)建spring boot的web項(xiàng)目,過(guò)程略;
二:依賴如下:
<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 * 文件說(shuō)明: */@Controllerpublic class FirstTestController { @RequestMapping(value = 'hello') public String hello(ModelMap modelMap) { modelMap.put('hei', 'thymeleaf'); return 'success'; }}
六:訪問(wèn)如下,完成
到此這篇關(guān)于SpringBoot使用Thymeleaf模板引擎訪問(wèn)靜態(tài)html的過(guò)程的文章就介紹到這了,更多相關(guān)SpringBoot Thymeleaf模板訪問(wèn)靜態(tài)html內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. vue style width a href動(dòng)態(tài)拼接問(wèn)題的解決2. Java源碼解析之接口List3. 在vue中獲取wangeditor的html和text的操作4. python mysql 字段與關(guān)鍵字沖突的解決方式5. Python用K-means聚類算法進(jìn)行客戶分群的實(shí)現(xiàn)6. Java xml數(shù)據(jù)格式返回實(shí)現(xiàn)操作7. python編寫五子棋游戲8. 解決Android Studio Design界面不顯示layout控件的問(wèn)題9. 使用vue-cli創(chuàng)建項(xiàng)目并webpack打包的操作方法10. python讀取中文路徑時(shí)出錯(cuò)(2種解決方案)
