为了加强实体类中,特殊字段类型的可读性和省去数据类型的转换,我们今天尝试把Int类型,例如状态这种整型字段换做枚举, 下面是旧代码
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("gdt_targeting")
@ApiModel(value="Targeting对象", description="定向数据")
public class Targeting extends BaseEntity {
@ApiModelProperty(value = "主键")
@TableId(value = "id", type = IdType.ID_WORKER)
private Long id;
@ApiModelProperty(value = "定向ID")
@TableField("targeting_id")
private Long targetingId;
@ApiModelProperty(value = "定向名称")
@TableField("targeting_name")
private String targetingName;
@ApiModelProperty(value = "定向所属广告主账号ID")
@TableField("account_id")
private Long accountId;
@ApiModelProperty(value

本文介绍了如何在MyBatisPlus中将整型字段替换为枚举类型,以提高代码可读性和减少数据类型转换。通过配置YML或properties文件,配合特定的枚举类,实现了字段转换。同时,展示了实体类的更新以及业务实现和测试代码,确保转换的正确性。
最低0.47元/天 解锁文章
1891





