thymeleaf可以直接将从后台获取的数据传给js中使用。
- 后台接口示例:
@Controller
public class TestController {
@GetMapping("test")
public String test(Model model) {
model.addAttribute("test", "hello"); // 将"hello"赋值给键名为test的属性
return "index";
}
}
- js代码:
<script th:inline="javascript">
var test = [[${test}]];
console.log(test);
</script>
原文链接:
https://www.cnblogs.com/kingsonfu/p/10272925.html
供参考文章链接:
https://www.cnblogs.com/wwct/p/12143084.html
https://blog.csdn.net/u013848401/article/details/78601672
https://blog.csdn.net/qq_22860341/article/details/84646193