我可以看到我的引导模板使用 thymeleaf 和 Spring Boot。
当我请求 http://localhost:8080/student
引导资源工作良好,但是当我请求包含一些路径变量时,如 http://localhost:8080/student/3
bootstrap 无法上传。我从浏览器请求方法:GET 收到此错误
状态代码:400。它尝试请求像 http://localhost:8080/student/bootstrap.css
这样的引导文件。
我认为声明引导文件的路径没有任何问题,因为其他页面工作正常。 我的路径来自资源/静态/bootstrap.css 指南 我没有使用 WebMvcConfig,而是使用默认的 spring 安全性。
@RequestMapping( value = "/student/{id}", method = RequestMethod.GET)
public String izinEkle(Model model, @PathVariable int id) {
studentService.getStudentlById(id);
Izin izin = new Izin();
model.addAttribute("izin",izin);
return "izinGiris";
}
--
<head lang="en">
<title>HolyDayTracker</title>
<link href="../static/bootstrap.css" th:href="@{bootstrap.css}" rel="stylesheet" media="screen">
<link href="../static/style.css" th:href="@{style.css}" rel="stylesheet">
<script src="http://cdn.jsdelivr.net/webjars/jquery/2.1.4/jquery.min.js th:src="@{../webjars/jquery/2.1.4/jquery.min.js}"></script>
最佳答案
尝试在 thymeleaf href attr 值中添加前导斜杠/。并且您不需要额外的 href 属性,只需 th:href 即可。
<link th:href="@{/bootstrap.css}" rel="stylesheet" media="screen">
<link th:href="@{/style.css}" rel="stylesheet">
关于java - Spring Boot thymeleaf 无法加载 css 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42402259/