史上最全SpringBoot教程,从零开始带你深入♂学习(四)——web开发

284 阅读1分钟

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";
    }
}

三、运行测试

image

最后,祝大家早日学有所成,拿到满意offer,快速升职加薪,走上人生巅峰。 可以的话请给我一个三连支持一下我哟,我们下期再见

白嫖资料