Spring Boot数据休息时间戳解析错误
Posted
技术标签:
【中文标题】Spring Boot数据休息时间戳解析错误【英文标题】:Spring boot data rest timestamp parse error 【发布时间】:2019-03-16 02:24:56 【问题描述】:我正在尝试使用数据休息进行 CRUD 操作,但在将第一条记录插入数据库后,我无法从数据库中检索数据作为 json
这是我的代码:
模型类
@Entity
@Table(name="ledger_group")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
@EntityListeners(AuditingEntityListener.class)
@Data
public class LedgerGroup implements Serializable
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Integer id;
@Column(name = "key_code")
private Integer keyCode;
@Column(name="ledger_group")
private String ledgerGroupName;
@ManyToOne
@JoinColumn(name = "parent")
private LedgerGroup parent;
@OneToMany(mappedBy = "parent")
@JsonIgnore
private List<LedgerGroup> ledgerGroupList;
@CreatedDate
@Temporal(TemporalType.TIMESTAMP)
@Column(name="timestamp_created")
private Date timestampCreated;
@LastModifiedDate
@Temporal(TemporalType.TIMESTAMP)
@Column(name="timestamp_modified")
private Date timestampModified;
//bi-directional many-to-one association to LedgerAccount
@OneToMany(mappedBy="ledgerGroup", cascade = CascadeType.ALL)
@JsonIgnore
private List<LedgerAccount> ledgerAccounts;
//bi-directional many-to-one association to User
@Column(name="user_created")
private String createdBy;
//bi-directional many-to-one association to User
@Column(name="user_modified")
private String lastModifiedBy;
public LedgerGroup()
存储库
@RepositoryRestResource
public interface LedgerGroupRepository extends PagingAndSortingRepository<LedgerGroup, Integer>
这是来自浏览器的错误
这是来自控制台的错误
2018-10-11 10:27:27.911 WARN 11122 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Invalid Object Id definition for com.icloud.micro.model.LedgerGroup: cannot find property with name 'id'; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid Object Id definition for com.icloud.micro.model.LedgerGroup: cannot find property with name 'id' (through reference chain: org.springframework.hateoas.PagedResources["_embedded"]->java.util.Collections$UnmodifiableMap["ledgerGroups"]->java.util.ArrayList[0])]
【问题讨论】:
请提供 DB 端 id 名称。这是数据库端的汽车吗? 【参考方案1】:请删除此行
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
【讨论】:
以上是关于Spring Boot数据休息时间戳解析错误的主要内容,如果未能解决你的问题,请参考以下文章
java spring-boot错误:“无法解析符号jdbc”
Spring Boot - Font Awesome OTS 解析错误:转换失败