1. 程式人生 > >Springboot怎麼訪問html頁面

Springboot怎麼訪問html頁面

1. 在原有的專案resouces目錄下建立static包,並在static下建立pages,然後在pages包下hello.html.

這時你會發現hello.html並沒有在static中,它跑哪去了呢?開啟src下的webapp,發現有一個hello.htm,刪除web.xml,並將hello.html用滑鼠左鍵移到static目錄下;


hello.html程式碼:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Insert title here</title>
</head>
<body>
	<h1>springboot訪問第一個html頁面</h1>
</body>
</html>

1.1. 建立springboot配置檔案application.roperties

在建立resouces目錄下建立application.properties,建立完成後會出現一個綠葉圖示

開啟application.properties,新增如下配置:

spring.mvc.view.prefix=/pages/
spring.mvc.view.suffix=.html

1.2.修改SpringBootController中的程式碼

改成


1.3.測試

啟動Appliction中的main方法(springboot應用的入口)

開啟瀏覽器訪問http://localhost:8080/hello

效果:


測試成功