gpt4 book ai didi

java - 无法将数据作为列表从 spring Controller 传递到 View ?

转载 作者:太空宇宙 更新时间:2023-11-04 11:06:12 25 4
gpt4 key购买 nike

我使用以下 Controller 方法从数据库检索数据

@RequestMapping(value = {"/channel-detail"}, method = RequestMethod.GET)
public String channelDetail(ModelMap model) {
List<Channel> channels = channelService.findAll();
model.addAttribute("channelList", channels);
return "channel-detail";
}

在我的 html 页面中,我使用 Thymeleaf 传递此 channel 列表,如下所示

<li class="channel-box" th:each="channels, rowStat : ${channelList}">
<a th:href="@{/channels/channel-detail?channelId=__${channels.id}__}" >
<img th:src="@{/assets/dist/img/axn.png}" alt="AXN" />
<span class="chn-name">AXN</span>
</a>
</li>

我期望的是迭代循环并多次显示内容。我的数据库包含 3 组 channel 条目。所以内容应该显示3次。但当我加载 html 时它什么也没有显示。这里有什么问题吗?

感谢任何帮助

最佳答案

不确定为什么对单个 uri 使用括号

@RequestMapping(value = {"/channel-detail"}, method = RequestMethod.GET)

尝试使用

@RequestMapping(value = "/channel-detail", method = RequestMethod.GET)

打印 Controller 中的列表,并告诉我您是否在控制台中看到这些项目。

关于java - 无法将数据作为列表从 spring Controller 传递到 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46463217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com