我在Java中的實體如下:如何獲得內部類的所有屬性作爲Java的外部類的一部分,而轉換成JSON
@Entity
@Table(name="ENTITY_MASTER")
@JsonIgnoreProperties(ignoreUnknown=true)
public class EntityMaster implements Serializable
{
@Id
private EntityMasterPK entityMasterPK;
public EntityMasterPK getEntityMasterPK() {
return entityMasterPK;
}
public void setEntityMasterPK(EntityMasterPK entityMasterPK) {
this.entityMasterPK = entityMasterPK;
}
@Column(name="ENTITY_BUSINESS_NAME")
private String entityBusinessName;
@Column(name="ENTITY_BUSINESS_NAME_ALT_LANG")
private String entityBusinessNameAltLang;
@Column(name="IS_ACTIVE")
private String isActive;
@Column(name ="GROUP_NAME")
private String groupName;
@Column(name="ENTITY_DESCRIPTION")
private String entityDescription;
@Column(name="IS_SURROGATE")
private String isSurrogate;
@Column(name="IS_GL_ENTITY")
private String isgL;
@Column(name="RECORD_DELETE_ALLOWED")
private String recordDeleteAllowed;
@Column(name="IS_RPF_REQUIRED")
private String isRpfRequired;
@Column(name="LOCK_REQUIRED")
private String lockRequired;
public String getIsRpfRequired() {
return isRpfRequired;
}
public void setIsRpfRequired(String isRpfRequired) {
this.isRpfRequired = isRpfRequired;
}
public String getLockRequired() {
return lockRequired;
}
public void setLockRequired(String lockRequired) {
this.lockRequired = lockRequired;
}
public String getRecordDeleteAllowed() {
return recordDeleteAllowed;
}
public void setRecordDeleteAllowed(String recordDeleteAllowed) {
this.recordDeleteAllowed = recordDeleteAllowed;
}
public String getIsgL() {
return isgL;
}
public void setIsgL(String isgL) {
this.isgL = isgL;
}
@Embeddable
public static class EntityMasterPK implements Serializable
{
@Column(name="SOLUTION_ID")
private Integer solutionId;
@Column(name="ENTITY_NAME")
private String entityName;
public Integer getSolutionId() {
return solutionId;
}
public void setSolutionId(Integer solutionId) {
this.solutionId = solutionId;
}
public String getEntityName() {
return entityName;
}
public void setEntityName(String entityName) {
this.entityName = entityName;
}
}
public String getEntityBusinessName() {
return entityBusinessName;
}
public void setEntityBusinessName(String entityBusinessName) {
this.entityBusinessName = entityBusinessName;
}
public String getEntityBusinessNameAltLang() {
return entityBusinessNameAltLang;
}
public void setEntityBusinessNameAltLang(String entityBusinessNameAltLang) {
this.entityBusinessNameAltLang = entityBusinessNameAltLang;
}
public String getIsActive() {
return isActive;
}
public void setIsActive(String isActive) {
this.isActive = isActive;
}
public String getGroupName(){
return groupName;
}
public void setGroupName(String groupName){
this.groupName=groupName;
}
public String getIsSurrogate(){
return isSurrogate;
}
public void setIsSurrogate(String isSurrogate){
this.isSurrogate=isSurrogate;
}
public String getEntityDescription(){
return entityDescription;
}
public void setEntityDescription(String entityDescription){
this.entityDescription=entityDescription;
}
}
我想serailize以JSON格式該類發到我的前端 當我將其轉換成JSON我得到的東西,如:{"entityBusinessName":"..","groupName":"abbc","entityMasterPK":{"solutionId":"100","entityName":"abcd"},..}
我怎樣才能得到entityMasterPk的變量也作爲我希望我的JSON來是這個樣子的主要JSON:{"entityBusinessName":"..","groupName":"abbc","solutionId":"100","entityName":"abcd",..}
, 我正在使用jpa,如果任何人有解決這個問題,請幫忙。
使用前端所需的所有字段創建數據傳輸對象。手動設置您的對象變量。 –