【问题标题】:Can't load CSS in thymeleaf无法在百里香中加载 CSS
【发布时间】:2022-02-07 00:48:29
【问题描述】:

我使用此解决方案将一个百里香叶包含在另一个中。它解决了我的问题,但现在根本不加载 css 文件

Thymeleaf: Replace div with other pages on controllers

这是我的控制器:

@GetMapping("/allUsers")
    public String userList(Model theModel) {
        List<User> theUsers = userService.findAll();
        theModel.addAttribute("users", theUsers);
        return "dashboard :: setFragment(content_fragment='/admin/allUsers')";
    }

以及链接到css文件的html部分

        <link rel="stylesheet" type="text/css" href="/css/style.css">
        
        <script>
            $(function () {
                var includes = $('[data-include]');
                $.each(includes, function () {
                    var file = '/admin' + $(this).data('include') + '.html';
                    $(this).load(file);
                });
            });
        </script> 
        <title>Dashboard</title>
    </head>

    <body>
        <div th:insert="fragments/header :: header"></div>
        <div class="row">
            <div id="content" th:fragment="setFragment(content_fragment)">
                <div th:insert="fragments/dashboard :: aside" class="col-md-2 px-3"></div>
                <div th:insert="fragments/users :: users" class="col-md-10 py-3"></div>
            </div>
        </div>
    </body>
...

【问题讨论】:

    标签: html spring spring-boot spring-mvc thymeleaf


    【解决方案1】:

    我不熟悉这种语言,但是您可能必须按如下方式加载您的 css:

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

    使用来自https://www.baeldung.com/spring-thymeleaf-css-js的示例

    【讨论】:

      猜你喜欢
      • 2018-11-20
      • 2019-12-19
      • 2018-06-20
      • 1970-01-01
      • 1970-01-01
      • 2020-12-30
      • 1970-01-01
      • 2020-02-05
      • 2018-09-07
      相关资源
      最近更新 更多