javascript
Spring Boot结合thymeleaf
之前在Eclipse里寫了個Spring Boot響應(yīng)jsp的小demo,后來發(fā)現(xiàn)打成jar包導(dǎo)出之后找不到j(luò)sp文件了。經(jīng)過在網(wǎng)上查閱信息與資料,發(fā)現(xiàn)Spring Boot對于jsp的支持其實是不好的,而且在一些書中和官方都明確表示沒有辦法支持在jar包中打入jsp文件。雖然也有些朋友發(fā)現(xiàn)將Spring Boot的版本降到1.4.2,通過插件可以打進(jìn)去并且訪問到。但其實已經(jīng)說明了一個問題,也就是既然選用了Spring Boot,就不要再用jsp了。
講了那么多,現(xiàn)在來分享一下Spring Boot結(jié)合thymeleaf的實例。
由于在另一篇隨筆里已經(jīng)詳述過如何在Eclipse里構(gòu)建一個Spring Boot工程,這里就不再細(xì)說。
大致的目錄結(jié)構(gòu)如下
pom中的相關(guān)依賴如下
<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中相關(guān)配置如下
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即可跳轉(zhuǎn)到index.html了
?
轉(zhuǎn)載于:https://www.cnblogs.com/xuzichao/p/8624164.html
總結(jié)
以上是生活随笔為你收集整理的Spring Boot结合thymeleaf的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LoadRunner参数包含逗号
- 下一篇: 【转载】javascript下ie7,i