我是后端方面的新手,我想在我的项目中使用modelmapper。我知道如何在基本级别上使用modelmapper。
我的实体类有:
public class Content {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false, unique = true)
private int id;
@ManyToOne
@JsonIgnore
@JoinColumn(name = "userId",
referencedColumnName = "userId",
foreignKey = @ForeignKey(name = "fk_content_userId"))
private User user;
@Column(name = "title")
private String title;
@Column(name = "createdDate")
private Double createdDate;
}
public class User {
@Id
@Column(name = "userId", nullable = false, unique = true)
private String userId;
@Column(name = "name")
private String name;
@Column(name = "phoneNumber")
private String phoneNumber;
@Column(name = "email")
private String email;
}
还有我的React课:
public class Response {
private String title;
private Double createdDate;
private String userId;
}
那我想要什么?
有api的主体:
response: {
"title": "title",
"createdDate": "1616758604",
"userId": "101010"
}
我想将此响应转换为以下内容:
Content: {
"title": "title",
"createdDate": "1616758604",
"User" : {
"userId" : "101010"
"name" : "",
"phoneNumber" : "",
"email" : ""
}
}
注意:最后我用json格式写了“content”。但我需要java的。
暂无答案!
目前还没有任何答案,快来回答吧!