我想在" id"上添加两个名字。
比如@JsonProperty("value")
和@JsonProperty("id")
怎么做?
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "trainingProgramId", unique = true, nullable = false)
public class TrainingProgram {
`private Integer id;`
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
}
答案 0 :(得分:0)
您可以将id的值复制到另一个具有其他名称的属性中。
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "trainingProgramId", unique = true, nullable = false)
public class TrainingProgram {
private int id;
private int idDupe;
public TrainingProgram() {
idDupe = id;
}
public int getIdDupe() {
return this.idDupe;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
}
但更好的问题是:为什么需要重复的id值?如果调用者可以直接使用id而不是副本,这不是一个更好的设计吗?