java - 使用 Spring 引导将 list<object> 传递给 thymeleaf

标签 java spring maven spring-boot thymeleaf

我有 Controller 的一部分:

@RequestMapping(value = "1", method = RequestMethod.GET)
public String greeting(@RequestParam(value="1", required = false, defaultValue = "1") int id, Model model){

    List<Question> survey = surveyDAO.getSurveyById(id);
    model.addAttribute("survey", survey);
    return "showSurvey";
}

我尝试将 addAttribute List 传递到 thymeleaf 页面的地方。但在 thymeleaf 方面,我只收到“无法解决”错误。

showSurvey.html中的部分.html

<div class="col-sm-12">
    <table class="table table-hover">
        <tr th:each="survey: ${survey}">
            <td th:text="${survey">1</td>
            <!-- <td><a href="#" th:text="${message.name}">Title ...</a></td>-->
        </tr>
    </table>
</div>

使用 mvn package 打包然后运行 ​​jar 启动应用程序,它可以工作,但是当尝试在 showSurvey.html 上解析“调查”时崩溃所以 SurveyDAO.GetSurveyById(id); 实际上正常返回。

那么我应该如何传递列表然后显示其中的正确值呢?它有两个 int 和 String 来处理所有重要的事情。

最佳答案

你错过了一个正确的“}” - 我刚刚测试过这个,它工作正常:

<table>
    <tr th:each="survey : ${survey}">
        <td th:text="${survey}">1</td>
    </tr>
</table>

只是一个错字。

关于java - 使用 Spring 引导将 list<object> 传递给 thymeleaf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44225978/

相关文章:

eclipse - Tomcat 没有启动

spring - 在 Spring 数据中使用分页进行限制和偏移

java - gwt 2.7 maven 项目是否必须是多模块的?

java - ByteBuffer 可以实现 DataOutput/DataInput 吗?

Java For 循环问题

java - 是否可以在 myeclipse 中安装 apache derby eclipse 插件?

java - 从没有 throws 声明的泛型方法传播异常

java - 将正确的类加载器设置到 tomcat 容器内的 spring 上下文中

maven - 通过 Maven 从测试类运行 main 方法

java - 自动构建maven插件