สคริปต์ JavaScript ใน thymeleaf ไม่ทำงานเมื่อโหลดเพจ?

<!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>

นี่คือไฟล์ thymeleaf ของฉัน ฉันต้องการส่งคำขอ GET และเพิ่มปุ่มบางปุ่มลงในเพจเมื่อเพจโหลด แต่สคริปต์ของฉันไม่ต้องการทำงาน ฉันทำอะไรผิดที่นี่?

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

นี่คือวิธีที่ผมแสดงเพจ...


person randomboiguyhere    schedule 29.10.2019    source แหล่งที่มา
comment
หากสคริปต์ของคุณเหมือนกับที่คุณเพิ่มไว้ มันจะเป็นเพียง console.log   -  person Ayrton    schedule 29.10.2019
comment
รู้ได้อย่างไรว่าไม่ได้วิ่ง? กด f12 ไปที่คอนโซลแล้วค้นหาบันทึก คุณอาจต้องการทำการแจ้งเตือน ('Hello World')   -  person Carlos López Marí    schedule 29.10.2019


คำตอบ (1)


ไม่เหมือนกับ HTML ปกติ คุณต้องรีสตาร์ทเซิร์ฟเวอร์ Spring ของคุณหลังจากการเปลี่ยนแปลงเทมเพลต Thymeleaf แต่ละครั้ง

person randomboiguyhere    schedule 29.10.2019
comment
จำเป็นต้องสร้างใหม่เท่านั้นหากคุณนำเข้าเครื่องมือสำหรับนักพัฒนาสปริง - person Carlos López Marí; 29.10.2019