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 文件夾下面建立對(duì)應(yīng)的html,比如我這邊建立一個(gè)pages文件夾,然后再建立一個(gè)WelinkLogin的html界面。
3.完成
輸入地址:運(yùn)行輸入地址http://localhost:8080/pages/welinklogin.html

springboot配置html頁(yè)面
最近寫了一下springboot , 碰到了一個(gè)配置 html 的問題 , 專門 記錄一下
首先 說(shuō)明 , 有兩種 訪問html 的方式
1.通過后臺(tái)跳轉(zhuǎn)到 html 頁(yè)面
現(xiàn)在比較流行的開發(fā)模式就是 前后端分離, 在分離的情況下 , 就無(wú)法直接訪問到 html , 需要通過 后端來(lái)跳轉(zhuǎn)
(1.) 添加maven
<!-- 動(dòng)態(tài)頁(yè)面 -->
<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ā)時(shí)關(guān)閉緩存,不然沒法看到實(shí)時(shí)頁(yè)面(3) controller
@Controller
@RequestMapping("/delete/")
public class deleteController {
@RequestMapping("wrong")
public String index() {
return "wrong";
}
}注意 :
訪問方法跳轉(zhuǎn)頁(yè)面 方法請(qǐng)求加/ 返回到某一個(gè)頁(yè)面不用.后綴名 并且類上的注解改為@controller 不是@rest Controller
通過訪問 localhost:8080/delete/wrong 就可以訪問到 templates下的wrong.html頁(yè)面.
2.直接訪問 html 頁(yè)面
配置applicaiton.yml
不用通過方法訪問頁(yè)面
spring:
resources:
static-locations: classpath:/static/, classpath:/templates/就可以通過 localhost:8080/wrong.html 訪問
到此這篇關(guān)于SpringBoot 返回Html界面的文章就介紹到這了,更多相關(guān)SpringBoot Html界面內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringCloud學(xué)習(xí)筆記之OpenFeign進(jìn)行服務(wù)調(diào)用
OpenFeign對(duì)feign進(jìn)行進(jìn)一步的封裝,添加了springmvc的一些功能,更加強(qiáng)大,下面這篇文章主要給大家介紹了關(guān)于SpringCloud學(xué)習(xí)筆記之OpenFeign進(jìn)行服務(wù)調(diào)用的相關(guān)資料,需要的朋友可以參考下2022-01-01
java使用異或?qū)崿F(xiàn)變量互換和異或加密解密示例
這篇文章主要介紹了使用異或?qū)崿F(xiàn)變量互換和異或加密解密示例,需要的朋友可以參考下2014-02-02
maven?springboot如何將jar包打包到指定目錄
這篇文章主要介紹了maven?springboot如何將jar包打包到指定目錄,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12
Java動(dòng)態(tài)代理機(jī)制的實(shí)例詳解
這篇文章主要介紹了 Java動(dòng)態(tài)代理機(jī)制的實(shí)例詳解的相關(guān)資料,希望通過本文大家能夠掌握動(dòng)態(tài)代理機(jī)制,需要的朋友可以參考下2017-09-09

