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
效果:
總結
以上所述是小編給大家介紹的Springboot訪問html頁面的教程詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!