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 操作

4.已自動生成了相應的TrainingConverterImpl類


5.自動生成的實現類位置在target/generated-sources/annotations 的同級目錄下

6.更多的生成的方法,參考下面的博客
@Mapper注解的使用
7. 手動指定@Mappings的對應 , source對應轉換源的字段的字段的字段, target對應目標類的字段
