Dar*_*ria 2 spring thymeleaf webjars spring-boot twitter-bootstrap-4
我正在尝试使用Thymeleaf为我的Spring Boot项目添加bootstrap.
的index.html
<!DOCTYPE html >
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments/header :: header"> </head>
<body>
<div th:replace="@{'views/' + ${content}} :: ${content}"></div>
<div lang="en" th:replace="fragments/footer :: footer"> </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
footer.html
<div xmlns:th="http://www.thymeleaf.org" th:fragment="footer" >
<script th:src="@{/webjars/jquery/3.3.1/jquery.min.js}"></script>
<script th:src="@{/webjars/popper.js/1.12.9-1/umd/popper.min.js}"></script>
<script th:src="@{/webjars/bootstrap/4.0.0-1/js/bootstrap.min.js}" ></script>
</div>
Run Code Online (Sandbox Code Playgroud)
了header.html
<head xmlns:th="http://www.thymeleaf.org" th:fragment="header" >
<meta charset="UTF-8">
<title>?????? ???????????? ??</title>
<link th:rel="stylesheet" th:href="@{webjars/bootstrap/4.0.0-1/css/bootstrap.min.css} "/>
</head>
Run Code Online (Sandbox Code Playgroud)
MvcConfig.java
@Configuration
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("/webjars/")
.resourceChain(false);
}
}
Run Code Online (Sandbox Code Playgroud)
样式不适用于页面和抛出错误:
在jquery,bootstrap,popper中.
我怎么能解决这个问题?
谢谢.
为了更容易,我得到了webjars-locator:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.0.0-2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.30</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在我的页面,最后,我说:
<script th:src="@{/webjars/jquery/jquery.min.js}"></script>
<script th:src="@{/webjars/popper.js/umd/popper.min.js}"></script>
<script th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
Run Code Online (Sandbox Code Playgroud)
我没有在Spring启动中使用任何其他设置来使用.
| 归档时间: |
|
| 查看次数: |
8011 次 |
| 最近记录: |