java-Spring JPA返回实体对象时更改实体布尔变量名称
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-Spring JPA返回实体对象时更改实体布尔变量名称,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2811字,纯文字阅读大概需要5分钟。
内容图文
![java-Spring JPA返回实体对象时更改实体布尔变量名称](/upload/InfoBanner/zyjiaocheng/684/0d1fa633936e433ba0fbec22aeb9d6a0.jpg)
我有以下评论实体:
@Entity
@Table(name = "comment")
public class Comment extends AbstractEntity
和其中一列:
@Column(name = "is_deleted")
private Boolean isDeleted;
返回的注释对象将变量名称从isDeleted更改为Deleted.
当我从客户端调用中保存Comment对象时.如果我说isDeleted:false,而我得到的则是delete:null.如果我说delete:false,那么我得到的是delete:false.因此,看起来列名已删除,但不是isDeleted.
不知道为什么会这样.
整个评论实体代码:
package no.nsd.archivingportal.domain.comment;
import no.nsd.archivingportal.domain.AbstractEntity;
import no.nsd.archivingportal.domain.user.User;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.UUID;
@Entity
@Table(name = "comment")
public class Comment extends AbstractEntity {
@Type(type="pg-uuid")
@Column(name = "commented_entity")
private UUID commentedEntity;
@ManyToOne
@JoinColumn(name = "user_id")
private User author;
@Column(name = "content")
private String content;
@Column(name = "is_deleted")
private Boolean isDeleted;
public UUID getCommentedEntity() {
return commentedEntity;
}
public void setCommentedEntity(UUID commentedEntity) {
this.commentedEntity = commentedEntity;
}
public User getAuthor() {
return author;
}
public void setAuthor(User author) {
this.author = author;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Boolean getDeleted() {
return isDeleted;
}
public void setDeleted(Boolean deleted) {
isDeleted = deleted;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Comment comment = (Comment) o;
if (commentedEntity != null ? !commentedEntity.equals(comment.commentedEntity) : comment.commentedEntity != null)
return false;
if (author != null ? !author.equals(comment.author) : comment.author != null) return false;
if (content != null ? !content.equals(comment.content) : comment.content != null) return false;
return isDeleted != null ? isDeleted.equals(comment.isDeleted) : comment.isDeleted == null;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (commentedEntity != null ? commentedEntity.hashCode() : 0);
result = 31 * result + (content != null ? content.hashCode() : 0);
result = 31 * result + (isDeleted != null ? isDeleted.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Comment{" +
"commentedEntity=" + commentedEntity +
", author=" + author +
", content='" + content + '\'' +
", isDeleted=" + isDeleted +
'}';
}
}
解决方法:
我认为问题出在您的isDeleted属性的获取者/设置者.
因此,要么将属性名称更改为Deleted并保持您的getter / setter不变,要么更改您的getter / setter以更准确地反映属性名称
例如
public Boolean getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Boolean deleted) {
isDeleted = deleted;
}
内容总结
以上是互联网集市为您收集整理的java-Spring JPA返回实体对象时更改实体布尔变量名称全部内容,希望文章能够帮你解决java-Spring JPA返回实体对象时更改实体布尔变量名称所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。