Spring Boot百万美元无法加载css资源

时间:2017-02-22 21:05:32

标签: java spring spring-boot thymeleaf

我可以看到我的引导模板使用带弹簧靴的百里香。

当我请求http://localhost:8080/student bootstrap资源工作正常时,但是当我请求包含一些路径变量时,如http://localhost:8080/student/3 bootstrap无法上传。我从浏览器中收到此错误请求方法:GET 状态代码:400 。它尝试请求http://localhost:8080/student/bootstrap.css之类的引导程序文件。

我认为在声明引导程序文件的路径时没有任何问题,因为其他页面工作正常。 我的路径来自guide作为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>

1 个答案:

答案 0 :(得分:1)

尝试在百万美元的href attr值中添加前导斜杠/。而且你不需要额外的href属性,只需要:href就可以了。

<link th:href="@{/bootstrap.css}" rel="stylesheet" media="screen">
<link th:href="@{/style.css}" rel="stylesheet">