简体   繁体   English

thymeleaf 中的 JavaScript 脚本在页面加载时不运行?

[英]JavaScript script in thymeleaf doesn't run on page load?

<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <script type="text/javascript" th:inline="javascript">
            console.log("Hello world");
        </script>

        <h1 th:text="${makeCodeName}"></h1>
    </body>
</html>

This is my thymeleaf file.这是我的 thymeleaf 文件。 I want to make a GET Request and add some buttons to the page when the page loads, but my script doesn't want to run?我想发出 GET 请求并在页面加载时向页面添加一些按钮,但我的脚本不想运行? What am I doing wrong here?我在这里做错了什么?

    @CrossOrigin
    @GetMapping("/makes/{makeCodeName}")
    public String showCarModels(@PathVariable String makeCodeName, Model model){
        model.addAttribute("makeCodeName", makeCodeName);
        return "testMakes";
    }

This is how I am showing the page...这就是我显示页面的方式...

Unlike normal HTML, you need to restart your Spring server after each change to your Thymeleaf template..与普通的 HTML 不同,每次更改 Thymeleaf 模板后,您都需要重新启动 Spring 服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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