MapStruct作了什麼

MapStruct 插件spring

MapStruct是基於編譯階段代碼生成的,生成的轉換代碼在運行的時候跟通常的代碼同樣,沒有額外的性能損失app

代碼性能

@Mapper(componentModel = "spring",uses = {RoleMapper.class, DeptMapper.class, JobMapper.class},unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface UserMapper extends EntityMapper<UserDTO, User> {spa

}.net

上述代碼在編譯期間會生成實現類插件

uses = {RoleMapper.class, DeptMapper.class, JobMapper.class} 使用到的mapper @Component public class UserMapperImpl implements UserMapper { @Autowired private RoleMapper roleMapper; @Autowired private DeptMapper deptMapper; @Autowired private JobMapper jobMapper;code

public UserMapperImpl() {
}

public User toEntity(UserDTO arg0) {
   //具體實現代碼
}

public UserDTO toDto(User arg0) {
   //具體實現代碼
}

public List<User> toEntity(List<UserDTO> arg0) {
  //具體實現代碼
}

public List<UserDTO> toDto(List<User> arg0) {
    //具體實現代碼
}

protected Role roleSmallDTOToRole(RoleSmallDTO roleSmallDTO) {
   //具體實現代碼
}

protected Set<Role> roleSmallDTOSetToRoleSet(Set<RoleSmallDTO> set) {
    //具體實現代碼

} protected Job jobSmallDTOToJob(JobSmallDTO jobSmallDTO) { //具體實現代碼 }component

protected Dept deptSmallDTOToDept(DeptSmallDTO deptSmallDTO) {
    //具體實現代碼
}

protected RoleSmallDTO roleToRoleSmallDTO(Role role) {
    //具體實現代碼
}

protected Set<RoleSmallDTO> roleSetToRoleSmallDTOSet(Set<Role> set) {
    //具體實現代碼
}

protected JobSmallDTO jobToJobSmallDTO(Job job) {
   //具體實現代碼
}

protected DeptSmallDTO deptToDeptSmallDTO(Dept dept) {
    //具體實現代碼
}

}get

額外點:it

Set<RoleSmallDTO> set1 = new HashSet(Math.max((int)((float)set.size() / 0.75F) + 1, 16));

建立HashSet的時候爲何要調用Math.max((int)((float)set.size() / 0.75F) + 1, 16)

set.size() /0.75 +1  = 總的空間大小 0.75即爲加載因子

16 = HashSet的初始化大小。

相關文章
相關標籤/搜索