1.导入pom文件 ,版本号自定 <!--mapStruct依赖--> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-jdk8</artifactId> <version>1.2.0.CR1</version> </dependency> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>1.2.0.CR1</version> <scope>provided</scope> </dependency> 2.举例编写Training的双向枚举类TrainingConverter import org.mapstruct.Mapper; @Mapper(componentModel = "spring") public interface TrainingConverter { Training dtoToEntity(TrainingDto trainingDto); TrainingDto entityToDto(Training training); List<TrainingDto> listEntityToDto(List<Training> training); //pageEntityToDto也是支持的 // listEntityToDto 也支持 } 3.在maven工程结构的root 项下,如图操作maven clean和compile 操作
@Mapper注解的使用
7. 手动指定@Mappings的对应 , source对应转换源的字段的字段的字段, target对应目标类的字段