maven依赖
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.2.0.Final</version>
</dependency>
使用demo
@Mapper
public interface FlyTaskConvert {
FlyTaskConvert INSTANCE = Mappers.getMapper(FlyTaskConvert.class);
@Mappings({
@Mapping(target = "createTime", expression = "java(java.time.LocalDateTime.now())"),
@Mapping(target = "updateTime", expression = "java(java.time.LocalDateTime.now())"),
@Mapping(target = "createBy", expression = "java(com.gdu.pigx.app.util.UserUtil.getUserId())"),
@Mapping(target = "updateBy", expression = "java(com.gdu.pigx.app.util.UserUtil.getUserId())")
})
FlyTaskDO dispatchUnmannedAerialVehicleDTOToFlyTaskDO(DispatchUnmannedAerialVehicleDTO dispatchUnmannedAerialVehicleDTO);
}
问题
- lombok和mapstrut同时使用
需保证lombok在前mapstrut在后文章来源:https://uudwc.com/A/JwOBb
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.2.0.Final</version>
</dependency>
- 空指针问题
在使用MapStruct,idea2020.3版本在build项目的时候出现错误:java: Internal error in the mapping processor: java.lang.NullPointerException
解决:
Setting -->Build,Execution,Deployment -->Compiler -->User-local build加上参数:
-Djps.track.ap.dependencies=false文章来源地址https://uudwc.com/A/JwOBb