1.controller
@RequestMapping(value = "message", method = RequestMethod.GET)
public String messages(Model model) {
model.addAttribute("message", "hello");
return "index";
}
2.该方法不行
var m = ${message}; // not working
alert(m);
3.可行方法
<script th:inline="JavaScript">
/*<![CDATA[*/
var message = [[${message}]];
console.log(message);
/*]]>*/
</script>