mapstrut用法和问题

maven依赖


		<dependency>
			<groupId>org.mapstructgroupId>
			<artifactId>mapstructartifactId>
			<version>1.2.0.Finalversion>
		dependency>
		<dependency>
			<groupId>org.mapstructgroupId>
			<artifactId>mapstruct-processorartifactId>
			<version>1.2.0.Finalversion>
		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);
}



问题

  1. lombok和mapstrut同时使用

需保证lombok在前mapstrut在后

        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <scope>providedscope>
        dependency>


		<dependency>
			<groupId>org.mapstructgroupId>
			<artifactId>mapstructartifactId>
			<version>1.2.0.Finalversion>
		dependency>
		<dependency>
			<groupId>org.mapstructgroupId>
			<artifactId>mapstruct-processorartifactId>
			<version>1.2.0.Finalversion>
		dependency>
  1. 空指针问题

在使用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

你可能感兴趣的:(java)