Spring Boot制作个人博客-框架搭建(设计与规范,实体类构建)

Posted qq_48838980

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Boot制作个人博客-框架搭建(设计与规范,实体类构建)相关的知识,希望对你有一定的参考价值。

一、实体设计

1、实体关系

在这里插入图片描述

2、评论类自关联关系

在这里插入图片描述

二、实体类构建

1、博客实体类

在这里插入图片描述

package net.zjs.lrm.po;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

/**
 * 功能:博客实体类
 * 作者:zjs
 * 日期:2021-06-11
 */

@Entity(name = "t_blog")
@Table
public class Blog {

    @Id
    @GeneratedValue
    private Long id;  //主键
    private String title;   //标题
    private String content;   //内容
    private String firstPicture;  //首图
    private String flag;  //标记
    private Integer views;  //浏览次数
    private boolean appreciation;  //赞赏开启
    private boolean shareStatement;   //版权开启
    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 isShareStatement() {
        return shareStatement;
    }

    public void setShareStatement(boolean shareStatement) {
        this.shareStatement = shareStatement;
    }

    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 +
                ", shareStatement=" + shareStatement +
                ", commentabled=" + commentabled +
                ", published=" + published +
                ", recommend=" + recommend +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
}

2、博客分类实体类

在这里插入图片描述

package net.zjs.lrm.po;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * 功能:博客分类
 * 作者:zjs
 * 日期:2021-06-11
 */

@Entity(name = "t_type")
@Table
public class Type {

    @Id
    @GeneratedValue
    private Long id;
    private String name;

    public Type() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Type{" +
                "id=" + id +
                ", name='" + name + '\\'' +
                '}';
    }
}

3、博客标签实体类

在这里插入图片描述

package net.zjs.lrm.po;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * 功能:博客标签
 * 作者:zjs
 * 日期:2021-06-11
 */
@Entity(name = "t_tag")
@Table
public class Tag {

    @Id
    @GeneratedValue
    private Long id;
    private String name;

    public Tag() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Tag{" +
                "id=" + id +
                ", name='" + name + '\\'' +
                '}';
    }
}

4、博客评论

在这里插入图片描述

package net.zjs.lrm.po;

import javax.persistence.*;
import java.security.PrivateKey;
import java.util.Date;

/**
 * 功能:博客评论实体类
 * 作者:zjs
 * 日期:2021-06-11
 */
@Entity(name = "t_comment")
@Table
public class Comment {

    @Id
    @GeneratedValue

    private Long id;
    private String nickname;//昵称
    private String email; //邮箱
    private String content;//评论的内容
    private String avatar;//头像
    @Temporal(TemporalType.TIMESTAMP) //设置时间生成的格式
    private Date createTime;//创建时间

    public Comment() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public String toString() {
        return "Comment{" +
                "id=" + id +
                ", nickname='" + nickname + '\\'' +
                ", email='" + email + '\\'' +
                ", content='" + content + '\\'' +
                ", avatar='" + avatar + '\\'' +
                ", createTime=" + createTime +
                '}';
    }
}

5、用户类

在这里插入图片描述

package net.zjs.lrm.po;

import javax.persistence.*;
import java.util.Date;

/**
 * 功能:用户实体类
 * 作者:zjs
 * 日期:2021-06-11
 */
@Entity(name = "t_user")
@Table
public class User {

    @Id
    @GeneratedValue
    private Long id;
    private String nickname;//昵称
    private String username;//用户名
    private String password;//密码
    private String email;//邮箱
    private String avatar;//头像
    private Integer type;//类型
    @Temporal(TemporalType.TIMESTAMP) //设置时间生成的格式
    private Date createTime;//创建时间
    @Temporal(TemporalType.TIMESTAMP) //设置时间生成的格式
    private Date updateTime;//更新时间

    public User() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    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 "User{" +
                "id=" + id +
                ", nickname='" + nickname + '\\'' +
                ", username='" + username + '\\'' +
                ", password='" + password + '\\'' +
                ", email='" + email + '\\'' +
                ", avatar='" + avatar + '\\'' +
                ", type=" + type +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
}

6、处理实体类之间的关系

  • Blog类与Type类建立关系

在这里插入图片描述

  • Blog类与Tag类建立关系

在这里插入图片描述

  • Blog类与User类建立关系

在这里插入图片描述

  • Blog类与Comment类建立关系

在这里插入图片描述

7、处理评论类自关联的关系

在这里插入图片描述

  • 注意:每次添加完关系之后都要setter and getter

8、运行服务器,查看数据库

在这里插入图片描述

在这里插入图片描述

以上是关于Spring Boot制作个人博客-框架搭建(设计与规范,实体类构建)的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot制作个人博客-框架搭建(日志处理,页面处理)

Spring Boot制作个人博客目录

Spring Boot制作个人博客目录

Spring Boot制作个人博客目录

Spring Boot制作个人博客目录

Spring Boot制作个人博客-构建框架