简体   繁体   中英

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. 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? 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..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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