gpt4 book ai didi

mysql - CRUD 存储库不返回父类(super class)数据

转载 作者:行者123 更新时间:2023-11-30 22:09:35 25 4
gpt4 key购买 nike

我有一个类扩展了另一个类的一些基本属性。我正在使用 CRUD 存储库与我的 MySql 数据库进行通信。我没有获得基类中定义的字段的值。

例如:我将 createdBy 和 modifiedBy 设为 null。

实体类

@JsonInclude(JsonInclude.Include.NON_NULL)
@Entity
@Table(name = "user")
class User extends BaseEntity {

@JsonProperty("id")
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private String id;

@JsonProperty("firstName")
@Column(name = "first_name")
private String firstName;

@JsonProperty("lastName")
@Column(name = "last_name")
private String lastName;

/**
* @return the id
*/
public String getId() {
return id;
}

/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}

/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}

/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}

/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}

/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
}

基类

class BaseEntity {

@JsonProperty("createdBy")
@Column(name = "created_by")
public String createdBy;

@JsonProperty("modifiedBy")
@Column(name = "modified_by")
public String modifiedBy;

/**
* @return the createdBy
*/
public String getCreatedBy() {
return createdBy;
}

/**
* @param createdBy the createdBy to set
*/
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}

/**
* @return the modifiedBy
*/
public String getModifiedBy() {
return modifiedBy;
}

/**
* @param modifiedBy the modifiedBy to set
*/
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
}

存储库

@Transactional
public interface UserRepo extends CrudRepository < User, String > {}

服务实现方法

public User getUser(String userId) {
User user = gUnifyUserRepository.findOne(userId);
//Here the data for createdBy and modifiedBy is returned as null though i have value in DB
return response;
}

感谢任何帮助。

最佳答案

public class BaseEntity implements Serializable {

@LastModifiedDate
private Date lastModified;
@CreatedDate
private Date createdAt;

使用上面的代码,让我知道

关于mysql - CRUD 存储库不返回父类(super class)数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40533240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com