1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| package com.abc.utils;
import lombok.AllArgsConstructor; import lombok.Data; import org.junit.Test;
public class DiffTest {
@Test public void testDiff() { User before = new User(1L, "李明", 1, 19, ""); User after = new User(1L, "李华", null, 20, "工程师");
String operations = Diff.builder() .diffField("姓名", before.getName(), after.getName()) .diffField("性别", formatGender(before.getGender()), formatGender(after.getGender())) .diffField("年龄", String.valueOf(before.getAge()), String.valueOf(after.getAge())) .diffField("职位", before.getPosition(), after.getPosition()) .build();
System.out.println(operations); }
public String formatGender(Integer gender) { if (gender == null) { return null; } return gender == 1 ? "男" : "女"; }
@Data @AllArgsConstructor public static class User {
private Long id; private String name; private Integer gender; private Integer age; private String position;
}
}
|