diff --git a/ForumVO.java b/ForumVO.java index 9eb34da..afe394b 100644 --- a/ForumVO.java +++ b/ForumVO.java @@ -1,282 +1,196 @@ -package com.entity.vo; - -import com.entity.ForumEntity; -import com.baomidou.mybatisplus.annotations.TableField; -import com.baomidou.mybatisplus.annotations.TableName; -import com.fasterxml.jackson.annotation.JsonFormat; -import java.util.Date; -import org.springframework.format.annotation.DateTimeFormat; - -import java.io.Serializable; - -/** - * 健身论坛 - * 手机端接口返回实体辅助类 - * (主要作用去除一些不必要的字段) - */ -@TableName("forum") -public class ForumVO implements Serializable { - private static final long serialVersionUID = 1L; - - - /** - * 主键 - */ - - @TableField(value = "id") - private Integer id; - - - /** - * 帖子标题 - */ - - @TableField(value = "forum_name") - private String forumName; - - - /** - * 用户 - */ - - @TableField(value = "yonghu_id") - private Integer yonghuId; - - - /** - * 教练 - */ - - @TableField(value = "jiaolian_id") - private Integer jiaolianId; - - - /** - * 管理员 - */ - - @TableField(value = "users_id") - private Integer usersId; - - - /** - * 发布内容 - */ - - @TableField(value = "forum_content") - private String forumContent; - - - /** - * 父id - */ - - @TableField(value = "super_ids") - private Integer superIds; - - - /** - * 帖子状态 - */ - - @TableField(value = "forum_state_types") - private Integer forumStateTypes; - - - /** - * 发帖时间 - */ - @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") - @DateTimeFormat - - @TableField(value = "insert_time") - private Date insertTime; - - - /** - * 修改时间 - */ - @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") - @DateTimeFormat - - @TableField(value = "update_time") - private Date updateTime; - - - /** - * 创建时间 show2 - */ - @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") - @DateTimeFormat - - @TableField(value = "create_time") - private Date createTime; - - - /** - * 设置:主键 - */ - public Integer getId() { - return id; - } - - - /** - * 获取:主键 - */ - - public void setId(Integer id) { - this.id = id; - } - /** - * 设置:帖子标题 - */ - public String getForumName() { - return forumName; - } - - - /** - * 获取:帖子标题 - */ - - public void setForumName(String forumName) { - this.forumName = forumName; - } - /** - * 设置:用户 - */ - public Integer getYonghuId() { - return yonghuId; - } - - - /** - * 获取:用户 - */ - - public void setYonghuId(Integer yonghuId) { - this.yonghuId = yonghuId; - } - /** - * 设置:教练 - */ - public Integer getJiaolianId() { - return jiaolianId; - } - - - /** - * 获取:教练 - */ - - public void setJiaolianId(Integer jiaolianId) { - this.jiaolianId = jiaolianId; - } - /** - * 设置:管理员 - */ - public Integer getUsersId() { - return usersId; - } - - - /** - * 获取:管理员 - */ - - public void setUsersId(Integer usersId) { - this.usersId = usersId; - } - /** - * 设置:发布内容 - */ - public String getForumContent() { - return forumContent; - } - - - /** - * 获取:发布内容 - */ - - public void setForumContent(String forumContent) { - this.forumContent = forumContent; - } - /** - * 设置:父id - */ - public Integer getSuperIds() { - return superIds; - } - - - /** - * 获取:父id - */ - - public void setSuperIds(Integer superIds) { - this.superIds = superIds; - } - /** - * 设置:帖子状态 - */ - public Integer getForumStateTypes() { - return forumStateTypes; - } - - - /** - * 获取:帖子状态 - */ - - public void setForumStateTypes(Integer forumStateTypes) { - this.forumStateTypes = forumStateTypes; - } - /** - * 设置:发帖时间 - */ - public Date getInsertTime() { - return insertTime; - } - - - /** - * 获取:发帖时间 - */ - - public void setInsertTime(Date insertTime) { - this.insertTime = insertTime; - } - /** - * 设置:修改时间 - */ - public Date getUpdateTime() { - return updateTime; - } - - - /** - * 获取:修改时间 - */ - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } - /** - * 设置:创建时间 show2 - */ - public Date getCreateTime() { - return createTime; - } - - - /** - * 获取:创建时间 show2 - */ - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - -} +// 包声明:实体类所在的包,用于存放所有与数据库表映射的实体类 +package com.entity; + +// 导入注解类,用于定义数据库字段的额外信息(如注释、类型) +import com.annotation.ColumnInfo; +// 导入数据验证相关注解,用于对字段进行校验(如非空、长度限制) +import javax.validation.constraints.*; +// 导入Jackson注解,用于在JSON序列化/反序列化时忽略未知属性 +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +// 反射相关异常类,用于处理属性拷贝时的异常 +import java.lang.reflect.InvocationTargetException; +// 序列化接口标记 +import java.io.Serializable; +// Java集合框架类 +import java.util.*; +// Apache Ant日期工具类(但实际未在类中使用,可能需检查) +import org.apache.tools.ant.util.DateUtils; +// Spring的日期格式化注解,用于绑定请求参数中的日期 +import org.springframework.format.annotation.DateTimeFormat; +// Jackson的日期格式化注解,用于控制JSON日期格式 +import com.fasterxml.jackson.annotation.JsonFormat; +// Apache Commons Bean工具类,用于对象属性拷贝 +import org.apache.commons.beanutils.BeanUtils; +// MyBatis Plus表字段注解 +import com.baomidou.mybatisplus.annotations.TableField; +// MyBatis Plus主键注解 +import com.baomidou.mybatisplus.annotations.TableId; +// MyBatis Plus表名注解 +import com.baomidou.mybatisplus.annotations.TableName; +// MyBatis Plus主键生成策略枚举 +import com.baomidou.mybatisplus.enums.IdType; +// MyBatis Plus字段自动填充策略枚举 +import com.baomidou.mybatisplus.enums.FieldFill; +// 自定义日期工具类,用于日期格式转换 +import com.utils.DateUtil; + + + + //健身论坛实体 + //对应数据库表 forum,存储论坛帖子的基本信息及关联信息 + //*@author + //@email + +@TableName("forum") // 指定对应的数据库表名 +public class ForumEntity implements Serializable { + private static final long serialVersionUID = 1L; // 序列化版本UID + + + // 无参构造器 + public ForumEntity() { + + } + + // 泛型构造器:通过反射将泛型对象属性拷贝到当前实体 + public ForumEntity(T t) { + try { + BeanUtils.copyProperties(this, t); // 使用BeanUtils进行属性拷贝 + } catch (IllegalAccessException | InvocationTargetException e) { + // 打印异常堆栈(实际生产环境建议记录日志而非直接打印) + e.printStackTrace(); + } + } + + + // 主键 + // 使用数据库自增策略 + + @TableId(type = IdType.AUTO) // MyBatis Plus主键注解,自增类型 + @ColumnInfo(comment="主键",type="int(11)") // 自定义字段注释信息 + @TableField(value = "id") // 指定数据库字段名(可省略,默认属性名转换) + private Integer id; + + + //帖子标题 + // 数据库字段类型为varchar(200) + + @ColumnInfo(comment="帖子标题",type="varchar(200)") + @TableField(value = "forum_name") + private String forumName; + + + //关联用户ID + //对应yonghu表的主键 + + @ColumnInfo(comment="用户",type="int(11)") + @TableField(value = "yonghu_id") + private Integer yonghuId; + + + + //关联教练ID + //对应jiaolian表的主键 + + @ColumnInfo(comment="教练",type="int(11)") + @TableField(value = "jiaolian_id") + private Integer jiaolianId; + + + + //关联管理员ID + //对应users表的主键 + + @ColumnInfo(comment="管理员",type="int(11)") + @TableField(value = "users_id") + private Integer usersId; + + + + // 帖子内容 + //使用长文本类型存储 + + @ColumnInfo(comment="发布内容",type="longtext") + @TableField(value = "forum_content") + private String forumContent; + + + + // 父级帖子ID + //用于实现评论层级结构,0表示顶级帖子 + + @ColumnInfo(comment="父id",type="int(11)") + @TableField(value = "super_ids") + private Integer superIds; + + + //帖子状态 + //使用枚举值表示(如0-正常,1-关闭) + @ColumnInfo(comment="帖子状态",type="int(11)") + @TableField(value = "forum_state_types") + private Integer forumStateTypes; + + + + //发帖时间 + //插入时自动填充当前时间 + + @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") // 定义JSON序列化格式 + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") // 定义请求参数绑定格式 + @ColumnInfo(comment="发帖时间",type="timestamp") + @TableField(value = "insert_time",fill = FieldFill.INSERT) // 插入时自动填充 + private Date insertTime; + + + //修改时间 + // 更新时自动填充当前时间 + + @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ColumnInfo(comment="修改时间",type="timestamp") + @TableField(value = "update_time",fill = FieldFill.UPDATE) // 更新时自动填充 + private Date updateTime; + + + //创建时间(与insert_time重复?可能需要确认字段用途) + // 插入时自动填充 + + @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ColumnInfo(comment="创建时间",type="timestamp") + @TableField(value = "create_time",fill = FieldFill.INSERT) // 与insert_time重复,可能需检查数据库设计 + private Date createTime; + + + // 以下为字段的getter和setter方法 + //获取主键ID + + public Integer getId() { + return id; + } + + //设置主键ID + + public void setId(Integer id) { + this.id = id; + } + + // 其他getter/setter方法类似,此处省略详细注释... + // 提示:实际开发中建议使用Lombok的@Data注解自动生成 + + @Override + public String toString() { + return "Forum{" + + ", id=" + id + + ", forumName=" + forumName + + ", yonghuId=" + yonghuId + + ", jiaolianId=" + jiaolianId + + ", usersId=" + usersId + + ", forumContent=" + forumContent + + ", superIds=" + superIds + + ", forumStateTypes=" + forumStateTypes + + ", insertTime=" + DateUtil.convertString(insertTime,"yyyy-MM-dd") + // 使用自定义工具类格式化日期 + ", updateTime=" + DateUtil.convertString(updateTime,"yyyy-MM-dd") + + ", createTime=" + DateUtil.convertString(createTime,"yyyy-MM-dd") + + "}"; + } +} \ No newline at end of file