我可以看到我的启动模板使用百里香与春季启动。春季启动百里香无法加载css资源
当我请求http://localhost:8080/student
bootstrap资源工作良好,但是当我请求包括一些像http://localhost:8080/student/3
这样的路径变量时,bootstrap无法上传。我从浏览器收到此错误请求方法:GET 状态码:400。它试图请求像这样的引导文件http://localhost:8080/student/bootstrap.css
。
我不认为我有任何问题与声明引导文件的路径,因为其他网页工作正常。 而我的路径是从指南作为资源/静态/ bootstrap.css 我没有使用WebMvcConfig,我使用默认的弹簧安全。
@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>
这似乎是程序试图获取路径变量id作为bootstrap.css。我想我的变量请求路径有一些逻辑失败。我很困惑。任何帮助,将不胜感激。谢谢。 – celnmeh
[绝对vs相对URL]可能的重复(http://stackoverflow.com/questions/2005079/absolute-vs-relative-urls) – g00glen00b
这里的问题是'bootstrap.css'将是一个相对URL,并且'/student'和'/ student/3'是不同的级别,所以它们会相对指向'bootstrap.css'的不同位置。有很多解决方案,其中大部分可以在链接问题中找到。最常见的解决方案是使用绝对URL(如@shi所示)或在您的'
'部分设置'