日拱一卒:对象拷贝
2023-12-27 本文已影响0人
Tinyspot
1. JSON 拷贝
DataTarget target = JSON.parseObject(JSON.toJSONString(dataDTO), DataTarget.class);
2. Spring BeanUtils 拷贝
- BeanUtils 复制对象采用的是浅拷贝模式
import org.springframework.beans.BeanUtils;
BeanUtils.copyProperties(source, target);
3. Apache 拷贝
import org.apache.commons.beanutils.BeanUtils;
try {
BeanUtils.copyProperties(dest, orig);
} catch (Exception e) {
}