簡體   English   中英

傳遞清單 <object> 春季靴子到百里香

[英]Passing list<object> to thymeleaf with Spring boot

我有部分控制器:

@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";
}

我嘗試添加屬性列表<問題>以傳遞給百萬富翁頁面。 但在百里葉方面,我只能得到“無法解決”的錯誤。

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包打包然后運行jar啟動應用程序,它可以工作,但在嘗試解析showSurvey.html上的“調查”時崩潰所以SurveyDAO.GetSurveyById(id); 實際上回來了。

那么我應該如何通過列表然后顯示正確的值呢? 對於所有重要事項,它有兩個int和String。

你錯過了一個正確的“}” - 我剛試過這個,它運行正常:

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

只是一個錯字。

就像我在評論中所說,你的代碼看起來不正確。

像這樣修復你的代碼:

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM