曾经用过,记录一下
pom.xml
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.45</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.6.0</version>
</dependency>
jsp内引用
<script src="${pageContext.request.contextPath}/webjars/jquery/3.6.0/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/bootstrap/3.3.7/css/bootstrap.min.css" />
用springMvc的记得要在springMvc.xml里放行,不然会被拦截(/webjars/变红是正常的,因为项目没运行时这里没有这个文件夹)
<mvc:resources mapping="/webjars/**" location="/webjars/" />
html内引用(有thymeleaf情况下)
<script type="text/javascript" th:src="@{/webjars/jquery/3.6.0/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.min.js}"></script>
<link rel="stylesheet" th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}" />
没有thymeleaf的话直接./或../即可,webjars路径位置可以在网页控制台的Sources里看到
所以我这里用的是../
<script src="../webjars/jquery/3.6.0/jquery.min.js"></script>
<script src="../webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="../webjars/bootstrap/3.3.7/css/bootstrap.min.css"/>
最后还有个bootstrapValidator的依赖,引用方式应该差不多,但没有测试过(因为后面就没用这个做验证了)
<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>bootstrapValidator</artifactId>
<version>0.5.2</version>
</dependency>