Java 通过列表<;对象>;使用弹簧靴安装到thymeleaf

Java 通过列表<;对象>;使用弹簧靴安装到thymeleaf,java,spring,maven,spring-boot,thymeleaf,Java,Spring,Maven,Spring Boot,Thymeleaf,我有控制器的一部分: @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.

我有控制器的一部分:

@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";
}
@RequestMapping(value=“1”,method=RequestMethod.GET)
公共字符串问候语(@RequestParam(value=“1”,required=false,defaultValue=“1”)int-id,Model){
列表调查=surveyDAO.getSurveyById(id);
model.addAttribute(“调查”,调查);
返回“showSurvey”;
}
在这里,我尝试添加要传递到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>

1.
使用mvn包打包,然后运行jar启动应用程序,它可以工作,但在尝试解析showSurvey.html上的“survey”时崩溃,因此
SurveyDAO.GetSurveyById(id)实际上正确返回

那么,我应该如何传递列表,然后从中显示正确的值呢?它有两个int和String来表示所有重要的内容。

您缺少一个正确的“}”-我刚刚测试了这个,它工作正常:

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

1.

只是输入错误。

就像我在评论中说的,你的代码看起来不正确

按如下方式修复代码:

<div class="col-sm-12">
    <table class="table table-hover">
        <tr th:each="survey: ${survey}">
            <td th:text="${survey.id}">1</td> // id is a property of the Question class
        </tr>
    </table>
</div>

1//id是问题类的属性

1
看起来不对。它必须是这样的
1
。哦,是的,你说得对!虽然我只是拿出来试一下对象,但结果是一样的,thymeleaf根本无法解析传入列表。请同时发布stacktrace。是的,你是对的。原来那只是个打字错误。。。