1. 程式人生 > 其它 >Springboot(四)——web開發

Springboot(四)——web開發

Springboot(三)——web開發

靜態資源

四個目錄存放的靜態資源可以被我們識別,用來存放我們的html、css、js、圖片等檔案

"classpath:/META-INF/resources/"
"classpath:/resources/"
"classpath:/static/"
"classpath:/public/"

他們的優先順序是:resources>static(預設)>public

可以在配置檔案中制定靜態資源路徑

#制定靜態資源路徑
spring.mvc.static-path-pattern=/hello/,classpath:/study 

首頁

springboot首頁可以放到resources下,也可以放到resources/static或者resources/public都可以

一、在靜態資源目錄下新建index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>首頁</h1>
</body>
</html>

二、編寫controller層

@Controller
public class IndexController {

    @RequestMapping("/index")
    public String index(){
        return "index";
    }
}

三、執行測試