【问题标题】:how to get data of list inside list using thymeleaf ?如何使用 thymeleaf 获取列表内列表的数据?
【发布时间】:2017-08-24 07:26:54
【问题描述】:

我有两个实体参与者和 XrayFieldRadiology。他们有一对一的关系。所以每当我选择参与者时,也会选择相关的 XrayFieldRadiology。现在我需要在我的表格和表单上显示所有这些数据库。

我的 html 文件看起来像这样。

Xraystatusform.html

    <div class="box-body" >
                        <span class="successMessage" th:text="${dataSuccess}" style="color: green; align-self:flex-end"></span>
                        <table id="example1" class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>Person Id</th>
                                <th>First Name</th>
                                <th>Last Name</th>
                                <th>Age</th>
                                <th>Sex</th>
                                <th>District</th>
                                <th>VDC/MUNICIPAL</th>
                                <th>Ward No.</th>
                                <th>Xray Status</th>
                                <th>Remarks</th>
                                <th>Actions</th>
                            </tr>
                            </thead>
                            <tbody  th:each="persons : ${part}">
                                <form  method="post" th:action="@{/xraystatus(id=${persons.id})}" enctype="multipart/form-data" id="form1">
                                    <td th:text="${persons.id}" id="xrayid"></td>
                                    <td th:text="${persons.name}"></td>
                                    <td th:text="${persons.lastName}"></td >
                                    <td th:text="${persons.age}"></td>
                                    <td th:text="${persons.sex}"> </td>
                                    <td th:text="${persons.district}"></td>
                                    <td th:text="${persons.district}"></td>
                                    <td th:text="${persons.wardNo}"></td>

                                    <td>
                                        <div class="checkbox"  >
                                            <select name="xraystatus" onchange="yesnoCheck(this);" style="width:61px"  >
                                                <!--<option th:each="xraydata:${xraydata}" th:text="${xraydata.xrayStatus}"></option>-->
                                                <option value="">Select</option>
                                                <option value="1">Yes</option>
                                                <option value="0">No</option>
                                                <option value="2">Possible</option>
                                                <option value="3">Exempted</option>
                                            </select>
                                        </div>
                                    </td>


                                    <td >
                                        <!--<div id="ifYes6" style="display:none; height:30px" >-->
                                            <input type="text" name="remarks"  >
                                        <!--</div>-->
                                    </td>
                                    <td><button type="submit" class="btn btn-success" >Submit</button> </td>
                                </form>

                            </tbody>
                        </table>
                    </div>

我的控制器返回这样的数据。

data picture

在我的输入字段备注中,我需要加载备注数据,例如这里的盲人。在 xraystatus 上,例如 0,1(根据数据库)。

到目前为止,我的桌子是这样的。

table

那么通过使用 thymeleaf 我如何访问列表中的列表?

【问题讨论】:

    标签: java html spring-boot thymeleaf


    【解决方案1】:

    如果我没看错你的数据,它应该很简单:

    <input type="text" name="remarks" th:value="${persons.xrayFieldRadiology != null ? persons.xrayFieldRadiology.remarks : ''}" />
    

    【讨论】:

    • 非常感谢,但是我遇到了另一个问题。如果所有行都在获取数据,那么它可以工作,但如果返回 null,则会引发错误。在我的情况下,如果没有返回数据,则该字段应该为空,否则应该添加返回的数据。
    • 现在很好用。我试图使用像这样的条件表达式 ${persons.xrayFieldRadiology.remarks } ?${persons.xrayFieldRadiology.remarks} : 'none' 但你在那里编辑的内容完美无缺。非常感谢您花时间和精力帮助我。我会将您的答案标记为有用。
    猜你喜欢
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 1970-01-01
    • 2018-10-10
    • 2018-08-09
    • 1970-01-01
    相关资源
    最近更新 更多