在Spring Boot框架下的web评论系统,实体类有评论、子评论、用户和回复,给出SQLServer数据库表的设计及其代码和实体类代码
时间: 2024-05-03 07:17:54 浏览: 17
SQLServer数据库表设计:
评论表(comment):
| 字段 | 类型 | 主键 | 自增 | 允许为空 |
| -------------- | -------------- | ---- | ---- | -------- |
| comment_id | int | 是 | 是 | 否 |
| user_id | int | | | 否 |
| content | varchar(MAX) | | | 否 |
| create_time | datetime | | | 否 |
| parent_id | int | | | 是 |
子评论表(sub_comment):
| 字段 | 类型 | 主键 | 自增 | 允许为空 |
| -------------- | -------------- | ---- | ---- | -------- |
| sub_comment_id | int | 是 | 是 | 否 |
| user_id | int | | | 否 |
| content | varchar(MAX) | | | 否 |
| create_time | datetime | | | 否 |
| parent_id | int | | | 否 |
| reply_to_id | int | | | 否 |
用户表(user):
| 字段 | 类型 | 主键 | 自增 | 允许为空 |
| ---------- | ------------ | ---- | ---- | -------- |
| user_id | int | 是 | 是 | 否 |
| username | varchar(50) | | | 否 |
| password | varchar(255) | | | 否 |
回复表(reply):
| 字段 | 类型 | 主键 | 自增 | 允许为空 |
| ---------- | ------------ | ---- | ---- | -------- |
| reply_id | int | 是 | 是 | 否 |
| user_id | int | | | 否 |
| content | varchar(MAX) | | | 否 |
| create_time| datetime | | | 否 |
| parent_id | int | | | 否 |
| to_user_id | int | | | 否 |
代码如下:
评论表(Comment):
```java
@Entity
@Table(name = "comment")
public class Comment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer commentId;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id", referencedColumnName = "user_id")
private User user;
private String content;
@Temporal(TemporalType.TIMESTAMP)
private Date createTime;
private Integer parentId;
// getter、setter方法
}
```
子评论表(SubComment):
```java
@Entity
@Table(name = "sub_comment")
public class SubComment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer subCommentId;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id", referencedColumnName = "user_id")
private User user;
private String content;
@Temporal(TemporalType.TIMESTAMP)
private Date createTime;
private Integer parentId;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "reply_to_id", referencedColumnName = "sub_comment_id")
private SubComment replyTo;
// getter、setter方法
}
```
用户表(User):
```java
@Entity
@Table(name = "user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer userId;
private String username;
private String password;
// getter、setter方法
}
```
回复表(Reply):
```java
@Entity
@Table(name = "reply")
public class Reply {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer replyId;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id", referencedColumnName = "user_id")
private User user;
private String content;
@Temporal(TemporalType.TIMESTAMP)
private Date createTime;
private Integer parentId;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "to_user_id", referencedColumnName = "user_id")
private User toUser;
// getter、setter方法
}
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)