有没有办法将 String 值从我的 Spring Controller 类传递到我的 HTML?在各种“ Hello World ”的例子中,他们说要使用
ModelAndView model = new ModelAndView("htmlPageName");
model.addAttribute("variableName", "someValue");
在 Controller 中
${variableName}
在 HTML 中。但是当我加载页面时,它显示的是 ${variableName}
而不是 "someValue"
我错过了什么吗?
最佳答案
如果你使用 Thymeleaf
<h1 th:text="${variableName}"></h1>
您写道:{$variableName} 而不是 ${variableName}
关于java - 通过 Spring 将数据从 Java 传递到 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50485083/