美文网首页
日拱一卒:对象拷贝

日拱一卒:对象拷贝

作者: Tinyspot | 来源:发表于2023-12-27 18:26 被阅读0次

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) {
}

相关文章

网友评论

      本文标题:日拱一卒:对象拷贝

      本文链接:https://www.haomeiwen.com/subject/kyzrndtx.html