ajax中使用thymeleaf的变量
在使用Ajax时,可以通过Thymeleaf的th:inline指令将Thymeleaf变量注入到JavaScript中,例如:
<script th:inline="javascript">
var username = /*[[${user.username}]]*/ '';
var userId = /*[[${user.id}]]*/ '';
// ...
</script>
在这个例子中,使用了Thymeleaf的th:inline指令将JavaScript代码标记为Thymeleaf模板。然后,使用/[[...]]/语法将Thymeleaf变量注入到JavaScript中。这样,在JavaScript中就可以使用这些变量了。
原文地址: https://www.cveoy.top/t/topic/baBD 著作权归作者所有。请勿转载和采集!