SpringBoot Web静态资源记录

知识点1,webjars方式引入第三方公共资源

使用jar包形式引入资源,网址如下:https://www.webjars.org/

这里举例使用jquery

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery</artifactId>
    <version>3.5.1</version>
</dependency>

使用在这里插入图片描述
在这里插入图片描述

知识点2,第三方公共资源放入指定文件夹

├── WebMvcAutoConfiguration
│   ├── addResourceHandlers
│   │   ├── this.resourceProperties.getStaticLocations()
│   │   │   ├── staticLocations

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/",
			"classpath:/resources/", "classpath:/static/", "classpath:/public/" };

这里我们新建一个public目录,存放js
在这里插入图片描述

在这里插入图片描述
html资源

hello.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<script src="./js/jquery-3.5.1.min.js">
</script>
</head>
<body>
    <h1>使用 jQuery 输出 Hello World</h1>
    <p>1234</p>
</body>


<script type="text/javascript">
	$(document).ready(function(){
	    $("p").text("js/jquery-3.5.1.min.js");
	});
</script>

</html>

在这里插入图片描述

知识点3,默认首页

根据源代码,取名为index.html即可

		private Optional<Resource> getWelcomePage() {
			String[] locations = getResourceLocations(this.resourceProperties.getStaticLocations());
			return Arrays.stream(locations).map(this::getIndexHtml).filter(this::isReadable).findFirst();
		}

		private Resource getIndexHtml(String location) {
			return this.resourceLoader.getResource(location + "index.html");
		}

知识点4,资源默认路径切换

结合配置文件ResourceProperties,配置即可

spring.resources.static-locations=classpath:/res

知识点5,Thymeleaf配置

结合配置文件ThymeleafProperties,配置即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值