SpringBoot 返回Html界面的操作代碼
SpringBoot 返回Html界面
1.添加依賴spring-boot-starter-web
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
2.創(chuàng)建Html界面
在Resources/static 文件夾下面建立對應的html,比如我這邊建立一個pages文件夾,然后再建立一個WelinkLogin的html界面。
3.完成
輸入地址:運行輸入地址http://localhost:8080/pages/welinklogin.html
springboot配置html頁面
最近寫了一下springboot , 碰到了一個配置 html 的問題 , 專門 記錄一下
首先 說明 , 有兩種 訪問html 的方式
1.通過后臺跳轉(zhuǎn)到 html 頁面
現(xiàn)在比較流行的開發(fā)模式就是 前后端分離, 在分離的情況下 , 就無法直接訪問到 html , 需要通過 后端來跳轉(zhuǎn)
(1.) 添加maven
<!-- 動態(tài)頁面 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
(2.) 配置 application.yml
spring: thymeleaf: prefix: classpath: /templates # 訪問template下的html文件需要配置模板,映射 cache: false # 開發(fā)時關(guān)閉緩存,不然沒法看到實時頁面
(3) controller
@Controller @RequestMapping("/delete/") public class deleteController { @RequestMapping("wrong") public String index() { return "wrong"; } }
注意 :
訪問方法跳轉(zhuǎn)頁面 方法請求加/ 返回到某一個頁面不用.后綴名 并且類上的注解改為@controller 不是@rest Controller
通過訪問 localhost:8080/delete/wrong 就可以訪問到 templates下的wrong.html頁面.
2.直接訪問 html 頁面
配置applicaiton.yml
不用通過方法訪問頁面 spring: resources: static-locations: classpath:/static/, classpath:/templates/
就可以通過 localhost:8080/wrong.html 訪問
到此這篇關(guān)于SpringBoot 返回Html界面的文章就介紹到這了,更多相關(guān)SpringBoot Html界面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringCloud使用集中配置組件Config規(guī)避信息泄露
項目應用中,數(shù)據(jù)庫連接信息、Access-key、Secret-key等由于其及其敏感和特殊性,一旦泄露出去就很可能會使得應用遭到黑客攻擊,例如數(shù)據(jù)庫賬號密碼泄露可能導致“拖庫”,甚至數(shù)據(jù)丟失。此等事件偶有發(fā)生,那么,在分布式微服務項目中,怎么避免這種情況呢2022-07-07SpringBoot靜態(tài)資源CSS等修改后再運行無效的解決
這篇文章主要介紹了SpringBoot靜態(tài)資源CSS等修改后再運行無效的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12

Spring Cloud使用Feign進行遠程調(diào)用的操作指南

spring?boot如何通過自定義注解和AOP攔截指定的請求