bug_fix+historyview

Change-Id: I6f446c1b660a4322865cfcf5502c88cb772ca0a1
diff --git a/src/main/java/com/example/g8backend/entity/Post.java b/src/main/java/com/example/g8backend/entity/Post.java
index ac7ff20..1a3cd25 100644
--- a/src/main/java/com/example/g8backend/entity/Post.java
+++ b/src/main/java/com/example/g8backend/entity/Post.java
@@ -1,6 +1,7 @@
 package com.example.g8backend.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 
@@ -19,6 +20,10 @@
     private Timestamp createdAt;
     private String postType;
 
+    @TableField("view_count")
+    private Integer viewCount = 0;
+
+
     @Override
     public String toString() {
         return "Post{" +
@@ -28,6 +33,7 @@
                 ", postContent='" + postContent + '\'' +
                 ", createdAt=" + createdAt +
                 ", postType='" + postType + '\'' +
+                ", viewCount=" + viewCount +  // ✅ 更新 toString 方法
                 '}';
     }
 }
diff --git a/src/main/java/com/example/g8backend/entity/PostView.java b/src/main/java/com/example/g8backend/entity/PostView.java
new file mode 100644
index 0000000..72de7ca
--- /dev/null
+++ b/src/main/java/com/example/g8backend/entity/PostView.java
@@ -0,0 +1,20 @@
+package com.example.g8backend.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.IdType;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.time.LocalDateTime;
+
+@Data
+@Accessors(chain = true)
+@TableName("post_views") // 指定数据库表名
+public class PostView {
+        @TableId(value = "view_id", type = IdType.AUTO) // 主键映射为 view_id,自增
+        private Long viewId;
+        private Long userId;    // 对应 user_id 字段(自动驼峰转下划线)
+        private Long postId;    // 对应 post_id 字段(自动驼峰转下划线)
+        private LocalDateTime viewTime; // 对应 view_time 字段
+}
\ No newline at end of file