springboot用controller跳轉(zhuǎn)html頁面的實(shí)現(xiàn)
在學(xué)習(xí)SpringBoot的過程中遇到一個(gè)問題,因?yàn)镾pringBoot是集成了tomcat的,所以項(xiàng)目是打成jar包,通過SpringMVC注解的方式去運(yùn)行的,所以靜態(tài)頁面就放在maven工程的resources目錄下的templates目錄下所以怎么去跳轉(zhuǎn)是個(gè)問題,現(xiàn)在就是解決這個(gè)問題
首先看項(xiàng)目結(jié)構(gòu)
pom.xml文件依賴
<!-- 1.創(chuàng)建一個(gè)Maven工程,選擇jar類型項(xiàng)目2.引入SpringBootMaven依賴。 --> <!-- Maven parent 目的,聚合工程、繼承關(guān)系 --> <!--Spring parent 目的: 統(tǒng)一整合第三方框架依賴信息 (SpringBoot 支持依賴 不需要寫版本號(hào)) --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RELEASE</version> </parent> <dependencies> <!-- -springboot 整合Web組件 整合SpringMVC 就會(huì)把傳統(tǒng)方式的SpringMVC依賴的jar全部給下載來 --> <!-- 引入spring-boot-starter-web 幫你整合好所有相關(guān)的依賴jar包 原理 maven依賴傳遞 --> <!-- 原理: spring-boot-starter-parent< 中,整合號(hào)相關(guān) 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代碼,這里為了更加的清楚項(xiàng)目結(jié)構(gòu)帶上包的路徑
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配置文件中不需要寫任何東西
到此這篇關(guān)于springboot用controller跳轉(zhuǎn)html頁面的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)springboot controller跳轉(zhuǎn)html內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. moment轉(zhuǎn)化時(shí)間戳出現(xiàn)Invalid Date的問題及解決2. python爬蟲實(shí)戰(zhàn)之制作屬于自己的一個(gè)IP代理模塊3. 如何在jsp界面中插入圖片4. HTML 絕對(duì)路徑與相對(duì)路徑概念詳細(xì)5. WML的簡單例子及編輯、測試方法第1/2頁6. 詳解盒子端CSS動(dòng)畫性能提升7. 解決ajax請求后臺(tái),有時(shí)收不到返回值的問題8. asp批量添加修改刪除操作示例代碼9. .NET6打包部署到Windows Service的全過程10. ajax請求后臺(tái)得到j(luò)son數(shù)據(jù)后動(dòng)態(tài)生成樹形下拉框的方法
