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. Xml簡介_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理2. UDDI FAQs3. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案4. ASP常用日期格式化函數(shù) FormatDate()5. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法6. CSS可以做的幾個(gè)令你嘆為觀止的實(shí)例分享7. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能8. jsp+servlet實(shí)現(xiàn)猜數(shù)字游戲9. jsp文件下載功能實(shí)現(xiàn)代碼10. JSP之表單提交get和post的區(qū)別詳解及實(shí)例
