1、引入jar包
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.10</version>
</dependency>
2、测试
public static void main(String[] args) {
MwmReleaseVersion releaseVersion = new MwmReleaseVersion();
releaseVersion.setType("pad");
MwmReleaseVersion old = new MwmReleaseVersion();
old.setId("111111111111111111");
old.setType("phone");
BeanUtil.copyProperties(releaseVersion,old, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
System.out.println(JSON.toJSONString(old));
}
BeanUtil.copyProperties
:将第一个参数的元素值赋值给第二个参数,setIgnoreNullValue(true)
为忽略null值