需要使用th:inline="javascript"显式开启,即必须在<script></scipt>标签上加上
<script th:inline="javascript">
...
var data = [[${staffList}]];//获取后台model中的值
...
</script>
后台java
@GetMapping("/add/{merchantOrderId}")
public String add(@PathVariable("merchantOrderId") Long merchantOrderId,ModelMap modelMap)
{
//获取数据集合
modelMap.put("staffList", staffList);
return prefix + "/add";
}
参考https://www.cnblogs.com/aforever/p/12160650.html
本文介绍如何在Thymeleaf模板中使用th:inline=javascript属性将后台Java模型数据传递到前端JavaScript,实现数据的动态显示。通过具体代码示例,展示了如何在<script>标签中获取后台传来的staffList数据。
543

被折叠的 条评论
为什么被折叠?



