java - 进行 Hibernate 映射时,整个表未在 JSON 中显示
问题描述
该表已成功创建并填充了 H2 数据库中的信息,如下所示:
当使用 Spring boot 以 JSON 格式显示此表信息时,我只看到:
在这里您可以看到来自对象的代码片段
package com.share.sharelt.entity;
import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.Data;
import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
@Entity
@Data
@Table(name = "item_rental")
public class ItemRental {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "created")
private Date created;
@Column(name = "cost")
BigDecimal cost;
@Column(name = "rent_begin")
private Date rentBegin;
@Column(name = "rent_end")
private Date rentEnd;
@Column(name = "is_confirmed")
private boolean isConfirmed;
@JsonBackReference
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "renter_id", nullable = true)
private User user;
public ItemRental(){};
}
问题是我想查看整个表信息,更具体地说是“renter_id”列
解决方案
解决方案之一是创建一个DTO
类,该类将成为您的实体的JSON
包装器ItemRental
ItemRentalDTO
与 实体类UserDTO
的所有字段类似ItemRental
的东西User
链接:https ://www.baeldung.com/entity-to-and-from-dto-for-a-java-spring-application
推荐阅读
- c# - 如何开始 wopi 协议与 Web 版 Office 集成?使用azure部署wopi主机
- java - android 图库应用程序中从在线存储下载的图像和视频的时间戳不正确?
- java - 如何在 Windows 和 Java 11 上调试“软件导致连接中止:recv 失败”?
- flutter - Android 不支持所选的 imageFormatGroup
- c++ - 如何用无符号长乘法得到准确的结果?
- python - 无法在 Anuga 模型的 python2 环境中导入 gdal/ogr 模块
- java - 使用java在折线图上显示点时出错
- docker - 从用户定义的网络访问 docker 主机网络
- c# - 如何检查与linq中的列表输入是否相等
- python - 代码错误请纠正。请帮助。python初学者