Spring boot 如何在Thymeleaf中读取模型中设置的属性

Spring boot 如何在Thymeleaf中读取模型中设置的属性,spring-boot,thymeleaf,Spring Boot,Thymeleaf,我正在尝试使用spring boot Eleaf从模型中读取属性 @GetMapping("/summary") public String getSummaryScreen(Model model) { Application application= getApplicationData(); ClientValidationModel clientValidationModelView = getclientModel(); model.addAttr

我正在尝试使用spring boot Eleaf从模型中读取属性

@GetMapping("/summary")
public String getSummaryScreen(Model model) {       
    Application application= getApplicationData();
    ClientValidationModel clientValidationModelView = getclientModel();
    model.addAttribute("clientValidationModelView",clientValidationModelView);
    model.addAttribute("application",application);
    return "summary";
}
class application{
   private int applicationNumber;
   private string name;

   ... getter & setter
}
在Thymeleaf中,我试图读取应用程序值

<div th:text ="${application.applicationNumber}"></div>
在HTML上是get only
“org.thymeleaf.context.WebEngineContext$ServletContextAttributesMap@1f6b5bcf“

如果正确使用变量表达式,只能确保变量表达式之间没有空格:

<div th:text="${application}"></div>

经过一些思考,我发现问题的解决方案是使用变量名“application”来设置模型属性。我可以通过将属性名设置为“newapplication”来解决这个问题。

谢谢,是的,我使用的是正确的html文件,没有空间。我通过maven构建了这个项目,它成功了(我认为SpringBootRestart应该可以),但是现在我遇到了另一个问题,我无法访问类变量。我认为你写的问题也是正确的。请确保:th:text=“${application.applicationNumber}”>之间没有空格,如果它不起作用,请将变量applicationNumber导出到它自己的模型属性以测试:model.addAttribute(“applicationNumber”,application.getApplicationNumber());那么请试试我的其他建议。另外,getter的名称应该如下所示:getApplicationNumber(),以便Thymeleaf通过变量名.I.model.addAttribute(“applicationNumber”,application.getApplicationNumber())识别它;但在html上显示为org.thymeleaf.context.WebEngineContext$ServletContextAttributesMap@7e8999c3Actually我的应用程序类非常庞大,有很多嵌套类,问题在于内存溢出之类的东西
<div th:text="${application}"></div>
model.addAttribute("application", "test to see if the variable expression works");