实体类,需要重写equals和hashCode方法
@Data
public class SmPersonSinceGrandOpen {
/** 跑批日期 */
private String workdateSm;
/** 统计维度(年龄段/家庭) 0:年龄段,1:家庭非家庭 */
private String dimStatsSm;
/** 维度详情 18岁以下/18-25岁/26-35岁/36-45/46-50岁/51岁及以上/家庭/非家庭 */
private String dimDetailSm;
/** 人数 */
private String personNumSm;
/** 占比 */
private String percentSm;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SmPersonSinceGrandOpen that = (SmPersonSinceGrandOpen) o;
return Objects.equals(workdateSm, that.workdateSm) && Objects.equals(dimStatsSm, that.dimStatsSm) && Objects.equals(dimDetailSm, that.dimDetailSm) && Objects.equals(personNumSm, that.personNumSm) && Objects.equals(percentSm, that.percentSm);
}
@Override
public int hashCode() {
return Objects.hash(workdateSm, dimStatsSm, dimDetailSm, personNumSm, percentSm);
}
}
比较代码
SmPersonSinceGrandOpen sm1 = new SmPersonSinceGrandOpen();
sm1.setWorkdateSm("1");
sm1.setDimStatsSm("1");
sm1.setDimDetailSm("1");
sm1.setPersonNumSm("1");
sm1.setPercentSm("1");
SmPersonSinceGrandOpen sm2 = new SmPersonSinceGrandOpen();
sm2.setWorkdateSm("1");
sm2.setDimStatsSm("1");
sm2.setDimDetailSm("1");
sm2.setPersonNumSm("1");
sm2.setPercentSm("1");
System.out.println(sm1.equals(sm2));