thymeleaf在js中使用后台傳來的值


一:第一種方式

1.在頁面中加入如下代碼views(位置:views/tableauPage)

<div th:fragment="scripts(scripts)">
        <script th:inline="javascript">
            window.applicationMetadataId = [[${applicationMetadataId}]];
            window.searchId = [[${searchId}]];
            window.searchName = [[${searchName}]];
            window.remark = [[${remark}]];
        </script>
</div>

2.layouts中引入上面的代碼塊

<div th:replace="views/tableauPage :: scripts(~{this :: .custom-script})"></div>

3.js中使用

 var that = window.searchId;

 二:第二中方式

1.把值放入

 model.addAttribute("userName", userName);

2.頁面直接 ${'屬性名'}

 <span th:text="${userName}" >USER</span>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM