MapStruct 生成代码
MapStruct generate code
我正在根据参考指南学习使用 MapStruct。
eclipse 版本是
Eclipse Java 面向 Web 开发人员的 EE IDE。
版本:Kepler Service Release 2
pom.xml如下,与参考指南相同
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.map</groupId>
<artifactId>MapStruct</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<org.mapstruct.version>1.0.0.Final</org.mapstruct.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<configuration>
<defaultOutputDirectory>
${project.build.directory}/generated-sources
</defaultOutputDirectory>
<processors>
<processor>org.mapstruct.ap.MappingProcessor</processor>
</processors>
<options>
<mapstruct.suppressGeneratorTimestamp>
true</mapstruct.suppressGeneratorTimestamp>
<mapstruct.defaultComponentModel>cdi</mapstruct.defaultComponentModel>
</options>
</configuration>
<executions>
<execution>
<id>process</id>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@Mapper
public interface CarMapper {
CarMapper INSTANCE = Mappers.getMapper(CarMapper.class);
@Mapping(source = "name", target = "fullName")
CarDto car2CarDto(Car car);
}
说是构建工程时会生成实现代码。但是在target/generated-sources文件夹下好像没有生成
添加M2E插件后,使用mvn clean install
,代码生成
我正在根据参考指南学习使用 MapStruct。 eclipse 版本是
Eclipse Java 面向 Web 开发人员的 EE IDE。 版本:Kepler Service Release 2
pom.xml如下,与参考指南相同
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.map</groupId>
<artifactId>MapStruct</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<org.mapstruct.version>1.0.0.Final</org.mapstruct.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<configuration>
<defaultOutputDirectory>
${project.build.directory}/generated-sources
</defaultOutputDirectory>
<processors>
<processor>org.mapstruct.ap.MappingProcessor</processor>
</processors>
<options>
<mapstruct.suppressGeneratorTimestamp>
true</mapstruct.suppressGeneratorTimestamp>
<mapstruct.defaultComponentModel>cdi</mapstruct.defaultComponentModel>
</options>
</configuration>
<executions>
<execution>
<id>process</id>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@Mapper
public interface CarMapper {
CarMapper INSTANCE = Mappers.getMapper(CarMapper.class);
@Mapping(source = "name", target = "fullName")
CarDto car2CarDto(Car car);
}
说是构建工程时会生成实现代码。但是在target/generated-sources文件夹下好像没有生成
添加M2E插件后,使用mvn clean install
,代码生成