SpringBoot frame: Construction entity class

SpringBoot frame: Construction entity class



 

Built package

  • In the project com.xxxunder a new popacket, used to store the entity class

Creating Entity Framework

  • BlogEntity classes id、title、content、firstPicture、flag、views、appreaciation、shareStatment、commentabled、published、recommend、createTime、updateTimeinclude: . And set property values are all get、set、toStringmethods, and initializes an empty constructor
    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 +
                    '}';
        }
    }
  • TypeCategories include:id、name
  • TagCategories include:id、name
  • CommentCategories include:id、nickname、email、content、avatar、createTime
  • UserCategories include:id、niacname、username、passworrd、email、avatar、type、creataTime、updateTime
  • Construction of the above properties are get、set、toStringmethods and constructors

Creating correspondence between entities

  • Relationships between entities
    • Type 一对多 Blog
    • Blog 多对一 Type
    • In Blog.javaCreate a file of the Blog对应于Type的ManyToOnetype of relationship and create its set、getmethods. In Type.javaCreate a file of the Type对应于Blog的OneToManytype of relationship and create its set、getmethods. Similar to the relationship between the rest of the way to create the type of entity classes
      //Blog.java
      //被维护端
      @ManyToOne
          private Type type;
      
      //Type.java
      //维护端
      @OneToMany(mappedBy = "type")
          private List<Blog> blogs = new ArrayList<>();
  • Comments from class relationships
    • Parent comment parentCommentcorresponding to the sub comment commentis one to many relationship, in Comment.javaCreate an inline relationship between comments files and creates corresponding get、setmethod:
      @OneToMany(mappedBy = "parentComment")
          private List<Comment> replyComment = new ArrayList<>();
      
          @ManyToOne
          private Comment parentComment;

       

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/skygrass0531/p/12551203.html