webjars的作用就不说了,直接在项目中使用
- 引入依赖:在官网https://www.webjars.org/引入需要的依赖,如jquery等
<dependency> <groupId>org.webjars</groupId> <artifactId>jquery</artifactId> <version>3.3.1-1</version> </dependency> <dependency> <groupId>org.webjars</groupId> <artifactId>bootstrap</artifactId> <version>4.1.3</version> </dependency> <!-- 可以隐藏硬编码版本号 --> <!-- https://mvnrepository.com/artifact/org.webjars/webjars-locator --> <dependency> <groupId>org.webjars</groupId> <artifactId>webjars-locator</artifactId> <version>0.32</version> </dependency>
- 访问资源:http://localhost:8080/webjars/jquery/jquery.js
怎么在项目中引用自己的静态资源呢?
- 新建maven项目,打成jar包,新建项目在src/main/resources下添加自己的资源({name}/{version}),这里为方便只引用了一个图片,结构在如下:
- 点击pom.xml右击maven build 运行打包命令,如下图:点击Run,等打包成功在target下生成jar包
- 在springboot中引入jar包,jar包结构如下:
- 添加依赖
<dependency> <groupId>com.ltt</groupId> <artifactId>springboot-webjars</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>
4.引用资源即可访问: