springboot用controller跳轉html頁面的實現
在學習SpringBoot的過程中遇到一個問題,因為SpringBoot是集成了tomcat的,所以項目是打成jar包,通過SpringMVC注解的方式去運行的,所以靜態頁面就放在maven工程的resources目錄下的templates目錄下所以怎么去跳轉是個問題,現在就是解決這個問題
首先看項目結構
pom.xml文件依賴
<!-- 1.創建一個Maven工程,選擇jar類型項目2.引入SpringBootMaven依賴。 --> <!-- Maven parent 目的,聚合工程、繼承關系 --> <!--Spring parent 目的: 統一整合第三方框架依賴信息 (SpringBoot 支持依賴 不需要寫版本號) --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RELEASE</version> </parent> <dependencies> <!-- -springboot 整合Web組件 整合SpringMVC 就會把傳統方式的SpringMVC依賴的jar全部給下載來 --> <!-- 引入spring-boot-starter-web 幫你整合好所有相關的依賴jar包 原理 maven依賴傳遞 --> <!-- 原理: spring-boot-starter-parent< 中,整合號相關 jar依賴信息 --> <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>
controller代碼,這里為了更加的清楚項目結構帶上包的路徑
package cn.hd.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic class FTLIndexController { @RequestMapping('/ftlIndex') public String ftlIndex() { System.out.println('fff'); return 'user/index'; }}
html代碼直接截圖
訪問頁面
application.properties配置文件中不需要寫任何東西
到此這篇關于springboot用controller跳轉html頁面的實現的文章就介紹到這了,更多相關springboot controller跳轉html內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章: