最近搭建springboot練習項目的時候,將index.html文件放在templates文件下。項目啟動之后,直接訪問localhost/index.html報路徑錯誤的提示。而使用restful風格的路徑跳轉就可以,網上搜索資料之后,得出結果是springboot默認的靜態訪問路徑是static,而templates是默認的動態訪問路徑。
由此產生的問題是,如何設置讓springboot的默認訪問路徑是templates。
解決的辦法是將templates設置為靜態路徑,在application.properties中加入以下。
spring.resources.static-locations=classpath:/templates/
由此又產生的問題是在restful訪問url的時候,路徑會不會產生影響,畢竟springboot默認的動態訪問路徑是templates。待查。