thymeleaf 传递数据到js变量
如何把控制器传来的model中的值传递给js变量呢?
需要以下两个:
- <script th:inline="javascript">
- var message = [[${message}]]
1.controller
@RequestMapping(value = "message", method = RequestMethod.GET)
public String messages(Model model) {
model.addAttribute("message", "hello");
return "index";
}
2.not work
var m = ${message}; // not working
alert(m);
3.ok
<script th:inline="javascript">
/*<![CDATA[*/
var message = [[${message}]];
console.log(message);
/*]]>*/
</script>