SpringBoot Web(1) 静态资源导入探究 +首页自定义

静态资源导入

在springboot中 我们可以使用以下方式处理静态资源
1.webjars(不推荐使用)
2.public,static,/**,resources localhost:8080/
优先级 resources>static>public

测试

创建文件夹public
创建1.js

测试访问:

定义主界面

通过源码可以得知定义一个index.html放在 templates,public,static,/**,resources中的一个即可

推荐写法:
放到templates文件夹里,该文件夹的内容只能通过controller去访问

编写控制类

package com.jie.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

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

注意要想网页加载出来需要使用模板引擎

posted @ 2021-05-13 15:01  一个经常掉线的人  阅读(62)  评论(0)    收藏  举报