SpringBoot2.0:訪問靜態頁面之Hello World

1.創建SpringBoot項目

2.檢查Appcalition.class的位置:

打開pom.xml,比如項目的groupId爲com.gm,Application.java的位置應該在這個位置之下

3.在application.properties / application.yml(需要處理結構)中配置視圖參數:

高版本: spring.mvc.view.prefix=* | spring.mvc.view.suffix=.*

低版本:spring.view.prefix=* | spring.view.suffix=.*

4.在SpringBoot靜態資源文件夾static下創建html

注:路徑與3中配置對應

5.編寫Controller

6.運行Application.java,SpringBoot默認訪問端口8080,路徑爲:localhost:8080/demo,就可以看到頁面

7.注意:

第5步中類的註解不能設置爲@RestController,@RestController是Spring4.0新出的註解,效果爲@Repository和@Controller註解的結合,故用@RestController在訪問路徑時候是以字符串返回,而不是跳轉到demo.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章