在mybatis-plus中,通常使用生成器生成的实体类,封装的create和time,但是有时候我们的表并不对应:
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public abstract class BaseDomain implements Serializable {
private static final long serialVersionUID = -3281418615869606867L;
/**
* 主键
*/
@JsonFormat(shape = JsonFormat.Shape.STRING)
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}
这时候使用mybatis-plus时会报错,因为列不对应,所以使用注解将数据库中没有的列进行排除:
@TableName(value = "WaterHigh", excludeProperty = {"id", "createTime", "updateTime"})注解
“id”, “createTime”, "updateTime为排除的列