探索flutter框架开发的app在移动应用市场的潜力与挑战
555
2022-11-20
Beans拷贝忽略空对象
@Data@NoArgsConstructor@AllArgsConstructorpublic class Student { @ExcelProperty("name") private String name; @ExcelProperty("age") private Integer age; @JsonFormat( shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss" ) @ExcelProperty("birthday") private LocalDateTime birthday; private String birthdayStr; public Student(String name, Integer age, LocalDateTime birthday) { this.name = name; this.age = age; this.birthday = birthday; } public String getBirthdayStr() { System.out.println("------------getBirthdayStr--------------"); return birthday.toString(); }}
@Data@ToString@AllArgsConstructorpublic class StudentVo { @ExcelProperty("name") private String name; @ExcelProperty("age") private Integer age; @JsonFormat( shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss" ) @ExcelProperty("birthday") private LocalDateTime birthday; public StudentVo() { System.out.println("---------------vo construct---------------"); } private String birthdayStr; public StudentVo(String name, Integer age, LocalDateTime birthday) { this.name = name; this.age = age; this.birthday = birthday; } public String getBirthdayStr() { System.out.println("-----vo-------getBirthdayStr--------------"); return birthday.toString(); }}
Student student = new Student("2", 222, LocalDateTime.now()); student.setName(null); StudentVo studentVo = new StudentVo("2", 2, LocalDateTime.now()); studentVo.setBirthdayStr("sssss"); BeanUtils.copyProperties(student,studentVo,OrikaUtil.getNullPropertyNames(student)); System.out.println(studentVo.toString());
public static String[] getNullPropertyNames(Object source) { final BeanWrapper src = new BeanWrapperImpl(source); java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors(); Set
在这里插入代码片
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~