You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Thymeleaf填充轮班排班表内嵌子表无数据的问题求助

问题根因

你在子表中写的${firstShift}、${secondShift}都是直接从页面全局Model中获取属性,而非读取当前外层遍历得到的calendar_node对象的成员字段。你后端并未将firstShift这类班次列表单独放入全局Model,而是封装在calendarNodeList的每个DTO元素中,因此子表遍历不到任何数据。

另外你第一班次的写法存在冗余:已经通过th:each拿到了遍历对象employee,不需要再通过索引i从列表中二次取值。

修正代码

<table class = "table table-striped table-hover" id = "schedule_table">
    <thead>
        <tr>
            <th class = "th_schedule_table">Date</th>
            <th class = "th_schedule_table">First Shift</th>
            <th class = "th_schedule_table">Second Shift</th>
            <th class = "th_schedule_table">Third Shift</th>
        </tr>
    </thead>
    <tbody>
        <tr th:each = "calendar_node : ${calendarNodeList}">
            <td th:text = "${calendar_node.date}"></td>
            <td>
                <table>
                    <tbody>
                        <tr th:each = "employee : ${calendar_node.firstShift}">
                            <td th:text = "${employee}"></td>
                        </tr>
                    </tbody>
                </table>
            </td>
            <td>
                <table>
                    <tbody>
                        <tr th:each = "employee: ${calendar_node.secondShift}">
                            <td th:text = "${employee}"></td>
                        </tr>
                    </tbody>
                </table>
            </td>
            <td>
                <table>
                    <tbody>
                        <tr th:each = "employee: ${calendar_node.thirdShift}">
                            <td th:text = "${employee}"></td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
</table>

内容的提问来源于stack exchange,提问作者LosmiNCL

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 15:36:03