Bean 字段复制利器 MapStruct
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本文聊一个工具类,MapStruct ,它是一个在 dto,po(do/entity),vo 等这些 pojo 中转换字段的一个工具,在应用中经常有这样的转换,在 spring 和 apache-commons 中也有 BeanUtils 复制,但不够灵活, 我之前也用反射写过一个字段复制 ,这种复制一般来是是很大量的,用反射会使系统的性能降低,有一种更高效的办法就是使用字节码工具类生成这些代码,这时在编译期就把代码弄好了,并且出错也好调试。 除了 MapStruct ,类似的工具还有 Spring 的 BeanUtils ,apachecommons 的 BeanUtils Dozer - Mapper that copies data from one object to another using annotations and API or XML configuration. JMapper - Uses byte code manipulation for lightning-fast mapping. Supports annotations and API or XML configuration. ModelMapper - Intelligent object mapping library