日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Boot结合thymeleaf

發布時間:2023/12/18 javascript 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Boot结合thymeleaf 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

之前在Eclipse里寫了個Spring Boot響應jsp的小demo,后來發現打成jar包導出之后找不到jsp文件了。經過在網上查閱信息與資料,發現Spring Boot對于jsp的支持其實是不好的,而且在一些書中和官方都明確表示沒有辦法支持在jar包中打入jsp文件。雖然也有些朋友發現將Spring Boot的版本降到1.4.2,通過插件可以打進去并且訪問到。但其實已經說明了一個問題,也就是既然選用了Spring Boot,就不要再用jsp了。

講了那么多,現在來分享一下Spring Boot結合thymeleaf的實例。

由于在另一篇隨筆里已經詳述過如何在Eclipse里構建一個Spring Boot工程,這里就不再細說。

大致的目錄結構如下

pom中的相關依賴如下

<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.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-thymeleaf</artifactId> </dependency> </dependencies>

application.properties中相關配置如下

server.port=8080 server.session.timeout=10 spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html spring.thymeleaf.cache=false

入口類如下

package com.thymeleaf;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);} }

ctrl層demo如下

package com.thymeleaf.controller;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping;@Controller public class DemoController {@RequestMapping("/")public String index() {return "index";} }

然后啟動,在瀏覽器中輸入localhost:8080即可跳轉到index.html了

?

轉載于:https://www.cnblogs.com/xuzichao/p/8624164.html

總結

以上是生活随笔為你收集整理的Spring Boot结合thymeleaf的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。