在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";
}
}
SpringBoot Web(1) 静态资源导入探究 +首页自定义
原文:https://www.cnblogs.com/OfflineBoy/p/14764604.html