[英]Spring Boot thymeleaf unable to load css resource
我可以看到使用百里香和弹簧靴的引导模板。
当我请求http://localhost:8080/student
引导程序资源正常工作时,但是当我请求包含一些路径变量(例如http://localhost:8080/student/3
引导程序)时,无法上传。 我从浏览器“ 请求方法:获取状态代码:400”中收到此错误。 它尝试请求引导文件,例如http://localhost:8080/student/bootstrap.css
。
我认为声明引导文件的路径没有任何问题,因为其他页面可以正常工作。 我的路径来自resources / static / 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">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.