根据自我需求,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)

相关文章:

  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-06
  • 2021-07-27
  • 2021-11-10
  • 2022-01-16
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
相关资源
相似解决方案