目录
依赖
<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);
}
如何使用
标签:Mappings,映射,mapstruct,mapstrcut,import,org,UserPojoMapper From: https://www.cnblogs.com/jf666/p/17096093.htmlUser dbUser = UserPojoMapper.mapper.tifUser2User(tifUser);