Update JianshenkechengCollectionEntity.java

王刚注释
pz2femycj 4 months ago
parent c88ddc02de
commit 68613f0b1e

@ -1,195 +1,170 @@
// 包声明实体类包存放所有与数据库表映射的JavaBean对象
package com.entity; package com.entity;
// 字段注解:自定义数据库字段描述信息
import com.annotation.ColumnInfo; import com.annotation.ColumnInfo;
// 数据校验注解:非空、范围等验证规则
import javax.validation.constraints.*; import javax.validation.constraints.*;
// JSON序列化注解忽略未定义字段
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
// 反射异常类:用于处理属性拷贝时的异常
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
// 序列化接口标识
import java.io.Serializable; import java.io.Serializable;
// 集合工具类
import java.util.*; import java.util.*;
// Apache Ant日期工具代码中未实际使用建议检查是否冗余
import org.apache.tools.ant.util.DateUtils; import org.apache.tools.ant.util.DateUtils;
// Spring日期格式注解请求参数绑定
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
// Jackson日期格式注解响应数据格式化
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
// Bean工具类对象属性拷贝
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
// MyBatis Plus字段注解
import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableField;
// MyBatis Plus主键注解
import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableId;
// MyBatis Plus表名注解
import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.annotations.TableName;
// MyBatis Plus主键策略枚举
import com.baomidou.mybatisplus.enums.IdType; import com.baomidou.mybatisplus.enums.IdType;
// MyBatis Plus字段填充策略枚举
import com.baomidou.mybatisplus.enums.FieldFill; import com.baomidou.mybatisplus.enums.FieldFill;
// 自定义日期工具类
import com.utils.DateUtil; import com.utils.DateUtil;
/** @TableName("jianshenkecheng_collection") // 指定关联数据库表名
*
*
* @author
* @email
*/
@TableName("jianshenkecheng_collection")
public class JianshenkechengCollectionEntity<T> implements Serializable { public class JianshenkechengCollectionEntity<T> implements Serializable {
// 序列化版本UID类版本控制
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// 空参构造器JPA/MyBatis等框架需要
public JianshenkechengCollectionEntity() {
public JianshenkechengCollectionEntity() { }
}
public JianshenkechengCollectionEntity(T t) {
try {
BeanUtils.copyProperties(this, t);
} catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/** // 泛型构造器:通过反射将泛型对象属性拷贝到当前实体
* public JianshenkechengCollectionEntity(T t) {
*/ try {
@TableId(type = IdType.AUTO) // 使用Apache BeanUtils进行属性拷贝
@ColumnInfo(comment="主键",type="int(11)") BeanUtils.copyProperties(this, t);
@TableField(value = "id") } catch (IllegalAccessException | InvocationTargetException e) {
// 异常处理(建议生产环境改为日志记录)
e.printStackTrace();
}
}
// 主键字段
@TableId(type = IdType.AUTO) // 主键自增策略
@ColumnInfo(comment="主键",type="int(11)") // 字段注释主键数据库类型int(11)
@TableField(value = "id") // 映射数据库字段名(可省略,默认驼峰转下划线)
private Integer id; private Integer id;
// 关联健身课程ID外键
/** @ColumnInfo(comment="健身课程",type="int(11)") // 字段注释:关联健身课程表
* @TableField(value = "jianshenkecheng_id") // 数据库字段名
*/
@ColumnInfo(comment="健身课程",type="int(11)")
@TableField(value = "jianshenkecheng_id")
private Integer jianshenkechengId; private Integer jianshenkechengId;
// 关联用户ID外键
/** @ColumnInfo(comment="用户",type="int(11)") // 字段注释:关联用户表
* @TableField(value = "yonghu_id") // 数据库字段名
*/
@ColumnInfo(comment="用户",type="int(11)")
@TableField(value = "yonghu_id")
private Integer yonghuId; private Integer yonghuId;
// 收藏类型(需配合字典表或枚举类使用)
/** @ColumnInfo(comment="类型",type="int(11)") // 字段注释1-收藏 2-点赞等类型
*
*/
@ColumnInfo(comment="类型",type="int(11)")
@TableField(value = "jianshenkecheng_collection_types") @TableField(value = "jianshenkecheng_collection_types")
private Integer jianshenkechengCollectionTypes; private Integer jianshenkechengCollectionTypes;
// 收藏时间(插入时自动填充)
/** @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") // 数据库类型timestamp
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") @TableField(value = "insert_time",fill = FieldFill.INSERT) // 插入时自动填充
@DateTimeFormat
@ColumnInfo(comment="收藏时间",type="timestamp")
@TableField(value = "insert_time",fill = FieldFill.INSERT)
private Date insertTime; private Date insertTime;
// 创建时间与insert_time可能存在冗余
/**
*
*/
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
@DateTimeFormat @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ColumnInfo(comment="创建时间",type="timestamp") @ColumnInfo(comment="创建时间",type="timestamp")
@TableField(value = "create_time",fill = FieldFill.INSERT) @TableField(value = "create_time",fill = FieldFill.INSERT) // 与insert_time同样使用插入填充需确认业务需求
private Date createTime; private Date createTime;
// Getter/Setter方法
// ----------------------------
/** // 主键访问器
*
*/
public Integer getId() { public Integer getId() {
return id; return id;
} }
/**
*
*/
// 主键修改器
public void setId(Integer id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
/**
* // 健身课程ID访问器
*/
public Integer getJianshenkechengId() { public Integer getJianshenkechengId() {
return jianshenkechengId; return jianshenkechengId;
} }
/**
*
*/
// 健身课程ID修改器
public void setJianshenkechengId(Integer jianshenkechengId) { public void setJianshenkechengId(Integer jianshenkechengId) {
this.jianshenkechengId = jianshenkechengId; this.jianshenkechengId = jianshenkechengId;
} }
/**
* // 用户ID访问器
*/
public Integer getYonghuId() { public Integer getYonghuId() {
return yonghuId; return yonghuId;
} }
/**
*
*/
// 用户ID修改器
public void setYonghuId(Integer yonghuId) { public void setYonghuId(Integer yonghuId) {
this.yonghuId = yonghuId; this.yonghuId = yonghuId;
} }
/**
* // 收藏类型访问器
*/
public Integer getJianshenkechengCollectionTypes() { public Integer getJianshenkechengCollectionTypes() {
return jianshenkechengCollectionTypes; return jianshenkechengCollectionTypes;
} }
/**
*
*/
// 收藏类型修改器(建议使用枚举限定值)
public void setJianshenkechengCollectionTypes(Integer jianshenkechengCollectionTypes) { public void setJianshenkechengCollectionTypes(Integer jianshenkechengCollectionTypes) {
this.jianshenkechengCollectionTypes = jianshenkechengCollectionTypes; this.jianshenkechengCollectionTypes = jianshenkechengCollectionTypes;
} }
/**
* // 收藏时间访问器
*/
public Date getInsertTime() { public Date getInsertTime() {
return insertTime; return insertTime;
} }
/**
*
*/
// 收藏时间修改器(通常自动填充,无需手动设置)
public void setInsertTime(Date insertTime) { public void setInsertTime(Date insertTime) {
this.insertTime = insertTime; this.insertTime = insertTime;
} }
/**
* // 创建时间访问器
*/
public Date getCreateTime() { public Date getCreateTime() {
return createTime; return createTime;
} }
/**
*
*/
// 创建时间修改器通常自动填充需确认与insert_time的区别
public void setCreateTime(Date createTime) { public void setCreateTime(Date createTime) {
this.createTime = createTime; this.createTime = createTime;
} }
// 对象字符串表示(调试用)
@Override @Override
public String toString() { public String toString() {
return "JianshenkechengCollection{" + return "JianshenkechengCollection{" +
", id=" + id + ", id=" + id +
", jianshenkechengId=" + jianshenkechengId + ", jianshenkechengId=" + jianshenkechengId +
", yonghuId=" + yonghuId + ", yonghuId=" + yonghuId +
", jianshenkechengCollectionTypes=" + jianshenkechengCollectionTypes + ", jianshenkechengCollectionTypes=" + jianshenkechengCollectionTypes +
", insertTime=" + DateUtil.convertString(insertTime,"yyyy-MM-dd") + // 使用自定义工具类格式化日期注意格式化为yyyy-MM-dd会丢失时间精度
", createTime=" + DateUtil.convertString(createTime,"yyyy-MM-dd") + ", insertTime=" + DateUtil.convertString(insertTime,"yyyy-MM-dd") +
"}"; ", createTime=" + DateUtil.convertString(createTime,"yyyy-MM-dd") +
"}";
} }
} }
Loading…
Cancel
Save