0

我正在根据参考指南学习使用 MapStruct。日食版本是

面向 Web 开发人员的 Eclipse Java 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文件夹下生成

4

1 回答 1

1

添加M2E插件后,使用mvn clean install并生成代码。

于 2016-08-08T02:07:18.030 回答