zoukankan      html  css  js  c++  java
  • thymeleaf 将后端绑定数据直接传递js变量

    根据自我需求,thymeleaf可以直接将后端数据传递给js中进行使用,例如:

    1.后端接口数据:

    @Controller
    public
    class TestController { @RequestMapping(value = "test", method = RequestMethod.GET) public String test(Model model) { model.addAttribute("test", "hello"); return "index"; } }

    利用thymeleaf将其传递给js使用:

    <script th:inline="javascript">
    
        var test= [[${test}]];
        console.log(test);
    
    </script>

    注:[[…]]之间的内容可以被赋值。为了使其生效,必须在此标签或者任何父标签上有th:inline属性。此属性有三种值(text , javascript and none)

  • 相关阅读:
    跨域处理
    intellij idea远程调试
    sring boot特性
    spring mvc与struts2的区别
    jenkins集成sonar
    hibernate笔记
    python脚本
    python 字符框
    python操作
    python环境配置
  • 原文地址:https://www.cnblogs.com/kingsonfu/p/10272925.html
Copyright © 2011-2022 走看看