Package com.skgxsn.blog_idea2017.po; Import the javax.persistence *. ; Import java.util.Date; @Entity // have this corresponds to generating a database annotation before the @Table (name = "t_blog") // corresponding to the database name public class Blog { the @Id // identifier Id, on behalf of the primary key @GeneratedValue // generation strategy Id of Private Long the above mentioned id; Private String title; Private String Content; Private String firstPicture; Private String Flag; Private Integer views; Private boolean appreciation; private boolean shareStatment; private boolean commentabled; private boolean published; private boolean recommend; @Temporal(TemporalType.TIMESTAMP) //数据库时间转换 private Date createTime; @Temporal(TemporalType.TIMESTAMP) private Date updateTime; public Blog() { } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getFirstPicture() { return firstPicture; } public void setFirstPicture(String firstPicture) { this.firstPicture = firstPicture; } public String getFlag() { return flag; } public void setFlag(String flag) { this.flag = flag; } public Integer getViews() { return views; } public void setViews(Integer views) { this.views = views; } public boolean isAppreciation() { return appreciation; } public void setAppreciation(boolean appreciation) { this.appreciation = appreciation; } public boolean isShareStatment() { return shareStatment; } public void setShareStatment(boolean shareStatment) { this.shareStatment = shareStatment; } public boolean isCommentabled() { return commentabled; } public void setCommentabled(boolean commentabled) { this.commentabled = commentabled; } public boolean isPublished() { return published; } public void setPublished(boolean published) { this.published = published; } public boolean isRecommend() { return recommend; } public void setRecommend(boolean recommend) { this.recommend = recommend; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public Date getUpdateTime() { return updateTime; } public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } @Override public String toString() { return "Blog{" + "id=" + id + ", title='" + title + '\'' + ", content='" + content + '\'' + ", firstPicture='" + firstPicture + '\'' + ", flag='" + flag + '\'' + ", views=" + views + ", appreciation=" + appreciation + ", shareStatment=" + shareStatment + ", commentabled=" + commentabled + ", published=" + published + ", recommend=" + recommend + ", createTime=" + createTime + ", updateTime=" + updateTime + '}'; } }
Type 一对多 Blog
Blog 多对一 Type
//Blog.java //被维护端 @ManyToOne private Type type; //Type.java //维护端 @OneToMany(mappedBy = "type") private List<Blog> blogs = new ArrayList<>();
- Comments from class relationships
@OneToMany(mappedBy = "parentComment") private List<Comment> replyComment = new ArrayList<>(); @ManyToOne private Comment parentComment;