优秀开源(7)MapStruct和BeanUtils
序言
Mapstruct与BeanUtils之间的区别,并解释为什么Mapstruct更适合Java对象映射。
BeanUtils
Mapstruct
1.如何使用 新建一个springboot项目
2.源码分析
一步一步展示出来如何实现的
D:\Java\MyGit\oa1\target\generated-sources\annotations\com\bitauto\oa\copy
UserMapperImpl.java
package com.bitauto.oa.copy; import javax.annotation.Generated; @Generated( value = "org.mapstruct.ap.MappingProcessor", date = "2024-07-18T00:11:57+0800", comments = "version: 1.4.2.Final, compiler: javac, environment: Java 1.8.0_192 (Oracle Corporation)" ) public class UserMapperImpl implements UserMapper { @Override public UserDto toDTO(User user) { if ( user == null ) { return null; } UserDto userDto = new UserDto(); userDto.setUsername( user.getUsername() ); userDto.setIconUrl( user.getIconUrl() ); return userDto; } }
问题
BeanUtils和Mapstruct属于什么拷贝?
MapStruct 中是创建新的对象,也就是深拷贝。
就这个原理,自己玩一套别的
https://www.cnblogs.com/doflamingo/p/13623867.html
https://www.cnblogs.com/xd502djj/p/16567484.html
https://blog.csdn.net/xiyang_1990/article/details/129944240?spm=1001.2101.3001.6650.5&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-5-129944240-blog-135021929.235%5Ev43%5Epc_blog_bottom_relevance_base7&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-5-129944240-blog-135021929.235%5Ev43%5Epc_blog_bottom_relevance_base7&utm_relevant_index=10
https://mp.weixin.qq.com/s?__biz=MzAxNDEwNjk5OQ==&mid=2650472865&idx=1&sn=d52936c029a49d13a1fb1d6edb463afc&chksm=8397c9b9b4e040af92a372cd0b5c2f08905b21ffb8ff6e5143ff08610856c9fef4b6233cbfdf&scene=21#wechat_redirect
https://blog.csdn.net/qq_32954567/article/details/135021929
资料
https://blog.csdn.net/dmjxsy/article/details/133172027