我尝试了一些在bean之间传输数据的方法。 最快的方法是getset bean。 第二快的方法是org.springframework.cglib.beans.BeanCopier。 有没有比BeanCopier更快的方法?
LOGGER.info("getset start trans data");
commentList.stream().map(
comment -> {
CommentVO commentVO = new CommentVO();
commentVO.setId(comment.getId());
commentVO.setContent(comment.getContent());
return commentVO;
}
).collect(Collectors.toList());
LOGGER.info("getset trans data compelete");
LOGGER.info("Spring.BeanUtils start trans data");
commentList.stream().map(
comment -> {
CommentVO commentVO = new CommentVO();
BeanUtils.copyProperties(comment, commentVO);
return commentVO;
}
).collect(Collectors.toList());
LOGGER.info("Spring.BeanUtils trans data compelete");
LOGGER.info("BeanCopier start trans data");
commentList.stream().map(
comment -> {
CommentVO commentVO = new CommentVO();
BeanCopier beanCopier = BeanCopier.create(Comment.class, CommentVO.class, false);
beanCopier.copy(comment, commentVO, null);
return commentVO;
}
).collect(Collectors.toList());
LOGGER.info("BeanCopier trans data compelete");
LOGGER.info("FASTJSON start trans data");
commentList.stream().map(
comment -> JSON.parseObject(JSON.toJSONString(comment), CommentVO.class)
).collect(Collectors.toList());
LOGGER.info("FASTJSON trans data compelete");
结果:
14:21:09.343 [main] INFO com.southcn.nfplus.cmt.web.Main - getset start trans data
14:21:09.360 [main] INFO com.southcn.nfplus.cmt.web.Main - getset trans data compelete
14:21:09.360 [main] INFO com.southcn.nfplus.cmt.web.Main - Spring.BeanUtils start trans data
14:21:09.657 [main] INFO com.southcn.nfplus.cmt.web.Main - Spring.BeanUtils trans data compelete
14:21:09.657 [main] INFO com.southcn.nfplus.cmt.web.Main - BeanCopier start trans data
14:21:09.805 [main] INFO com.southcn.nfplus.cmt.web.Main - BeanCopier trans data compelete
14:21:09.805 [main] INFO com.southcn.nfplus.cmt.web.Main - FASTJSON start trans data
14:21:10.396 [main] INFO com.southcn.nfplus.cmt.web.Main - FASTJSON trans data compelete