首页 > 其他分享 >mapstrcut

mapstrcut

时间:2023-02-06 17:33:05浏览次数:51  
标签:Mappings 映射 mapstruct mapstrcut import org UserPojoMapper

目录

依赖

    <java.version>1.8</java.version>
    <org.mapstruct.version>1.3.0.Final</org.mapstruct.version>
</properties>
 <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-jdk8</artifactId>
        <version>${org.mapstruct.version}</version>
    </dependency>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
        <version>${org.mapstruct.version}</version>
        <scope>provided</scope>
    </dependency>

属性映射代码

点击查看代码
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * user类转化映射
 * @author JiangFeng
 * @since 2023/2/6
 */
@Mapper
public interface UserPojoMapper {
	// 写全先,写一半报错先不管
    UserPojoMapper mapper = Mappers.getMapper(UserPojoMapper.class);

    @Mappings({
        @Mapping(source = "name", target = "fullName")
    })
    User tifUser2User(TifUser tifUser);

}

如何使用

   User dbUser = UserPojoMapper.mapper.tifUser2User(tifUser);

标签:Mappings,映射,mapstruct,mapstrcut,import,org,UserPojoMapper
From: https://www.cnblogs.com/jf666/p/17096093.html

相关文章