spring boot 不会在页面上显示对象列表

用户468587

我有一个使用 SpringBoot 构建的简单 Web 应用程序,但在页面上显示对象列表时遇到问题:

这是我的模型:

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class Slot {
    private Long id;
    private DateTime startTime;
    private DateTime finishTime;
    private String title;
    private String description;
}

控制器:

@RestController
public class AdminController {
    @GetMapping("/admin/slots")
    public ModelAndView getSlots() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("admin/slots");

        List<Slot> slots = .. get slots from other service ..
        modelAndView.addObject("slots", slots);
        return modelAndView;
    }
}

看法:

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Slot List</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <table class="table" id="slot-table">
        <thead>
        <tr>
            <th>id</th>
            <th>start time</th>
            <th>finish time</th>
            <th>title</th>
            <th>description</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="slot : ${slots}">
            <td th:text="${slot.getId()}"></td>
            <td th:text="${slot.getStartTime()}"></td>
            <td th:text="${slot.getFinishTime()}"></td>
            <td th:text="${slot.getTitle()}"></td>
            <td th:text="${slot.getDescription()}"></td>
        </tr>
        </tbody>
    </table>
</body>
</html>

当我在浏览器中打开时,我可以看到表头但看不到表中的数据,我做错了什么吗?

外星人

要访问视图页面中的字段,您不必使用 getter 和 setter。只需使用点运算符访问,如下所示。

${slot.id}
${slot.startTime}
${slot.finishTime}
${slot.title}
${slot.description}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

JSP不会在Spring Boot 2中呈现Java列表

Hibernate不会在Spring Boot Project中引发LazyInitializationException

Spring Boot 不会在 Postgres 中创建表

Spring-boot应用程序不会在Docker内部启动时启动

Hibernate Validation不会在Spring Boot应用程序中查找错误消息

JPA左联接查询不会在Spring Boot中实例化子集合吗?

Spring Boot RabbitMQ死队列不会在异常时停止流

Spring Boot Jackson 不会在 Long 中序列化时间戳

Spring Boot父模块不会在子模块上更改时更新

Spring boot 不会在 CURL 结果上添加新实体

spring-boot-devtools不会在多模块maven项目中重新加载依赖的模块

Spring Boot Rest Security Basic Auth Password Encoder不会在登录时加密密码

Spring boot不会在Mysql上自动创建数据库表

Spring Boot RestTemplate列表

Spring Boot缓存列表

Spring Boot缓存列表

Spring Boot项目显示“登录”页面

Spring Boot替代索引页面

对象 Bean 验证的 Spring Boot 列表

如何调试,为什么Spring Boot集成测试上下文不会在测试之间重用?

事务性不会在 Spring Boot 中使用数据 JPA 回滚已检查的异常

Spring Boot WhiteLabel 错误页面 (Spring 4.0)

Kotlin Spring Boot @ConfigurationProperties的列表

Spring Boot Thymeleaf下拉列表

Spring Boot:在多个 html 页面上管理 API

Spring AOP切入点在列表内可用时,不会在对象的方法调用上触发

Django 模板不会在页面上显示模型对象属性

Spring Boot Jquery Controller Json不会追加到页面

如何遍历对象的ArrayList的ArrayList,并在Spring boot中以JSP页面的形式显示数据?