简体   繁体   English

Spring Boot thymeleaf无法加载CSS资源

[英]Spring Boot thymeleaf unable to load css resource

I can see my bootstrap template using thymeleaf with spring boot. 我可以看到使用百里香和弹簧靴的引导模板。

When I request http://localhost:8080/student bootstrap resources work good, but when I request including some path variable like http://localhost:8080/student/3 bootstrap can't be uploaded. 当我请求http://localhost:8080/student引导程序资源正常工作时,但是当我请求包含一些路径变量(例如http://localhost:8080/student/3引导程序)时,无法上传。 I'm getting this error from the browser Request Method:GET Status Code:400 . 我从浏览器“ 请求方法:获取状态代码:400”中收到此错误。 It tries to request bootstrap file like that http://localhost:8080/student/bootstrap.css . 它尝试请求引导文件,例如http://localhost:8080/student/bootstrap.css

I don't think I have any problems with declaring bootstrap files' path because other pages work fine. 我认为声明引导文件的路径没有任何问题,因为其他页面可以正常工作。 And my paths are from guide as resources/static/bootstrap.css I'm not using WebMvcConfig and I'm using default spring security. 我的路径来自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>

Try adding a leading slash / in your thymeleaf href attr value. 尝试在您的thymeleaf href attr值中添加一个前导斜杠/。 And you do not need additional href attributes, only th:href will do. 而且您不需要其他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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM