{"id":914,"date":"2023-03-11T17:05:36","date_gmt":"2023-03-11T09:05:36","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=914"},"modified":"2023-04-29T15:49:45","modified_gmt":"2023-04-29T07:49:45","slug":"thymleaf-passes-data-to-javascript-variables","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/11\/thymleaf-passes-data-to-javascript-variables\/","title":{"rendered":"Thymeleaf\u4f20\u9012\u6570\u636e\u5230js\u53d8\u91cf"},"content":{"rendered":"<p>\u5982\u4f55\u628a\u63a7\u5236\u5668\u4f20\u6765\u7684model\u4e2d\u7684\u503c\u4f20\u9012\u7ed9js\u53d8\u91cf\u5462?<\/p>\n<h2>Controller<\/h2>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">@RequestMapping(value\u00a0=\u00a0&quot;message&quot;,\u00a0method\u00a0=\u00a0RequestMethod.GET)\npublic\u00a0String\u00a0messages(Model\u00a0model)\u00a0{\n    model.addAttribute(&quot;message&quot;,\u00a0&quot;hello&quot;);\n    return\u00a0&quot;index&quot;;\n}<\/code><\/pre>\n<h2>not work<\/h2>\n<pre><code class=\"language-javascript\">var m = ${message}; \/\/ not working\nalert(m);<\/code><\/pre>\n<h2>ok<\/h2>\n<pre><code class=\"language-html\">&lt;script th:inline=&quot;javascript&quot;&gt;\n\/*&lt;![CDATA[*\/\n\n    var message = [[${message}]];\n    console.log(message);\n\n\/*]]&gt;*\/\n&lt;\/script&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u628a\u63a7\u5236\u5668\u4f20\u6765\u7684model\u4e2d\u7684\u503c\u4f20\u9012\u7ed9js\u53d8\u91cf\u5462? Controller @RequestMapping(v [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[156],"class_list":["post-914","post","type-post","status-publish","format-standard","hentry","category-spring-boot","tag-thymeleaf"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=914"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/914\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}