0

我正在使用 Mapstruct 为我的实体生成 dto 对象。我在笔记本电脑上的土耳其语 Windows 10 上使用 IntelliJ。我的问题如下。

 @Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2016-09-05T16:36:08+0300",
    comments = "version: 1.0.0.Final, compiler: javac, environment: Java 1.8.0_74 (Oracle Corporation)"
)
public class VeininvoiceMapperImpl implements VeininvoiceMapper {

    private final LocalDateMapper localDateMapper = Mappers.getMapper( LocalDateMapper.class );
    private final BoxTypeMapper boxTypeMapper = Mappers.getMapper( BoxTypeMapper.class );
    private final InvoiceStatusCodeMapper ınvoiceStatusCodeMapper = Mappers.getMapper( InvoiceStatusCodeMapper.class );
    private final SenderLabelMapper senderLabelMapper = Mappers.getMapper( SenderLabelMapper.class );
    private final PostboxLabelMapper postboxLabelMapper = Mappers.getMapper( PostboxLabelMapper.class );
    private final VeinpartnerMapper veinpartnerMapper = Mappers.getMapper( VeinpartnerMapper.class );

    @Override
    public Invoice veininvoiceToDto(Veininvoice veininvoice) {
        if ( veininvoice == null ) {
            return null;
        }

        Invoice ınvoice = new Invoice();

        ınvoice.setInvoiceStatusCode( ınvoiceStatusCodeMapper.statusToDto( veininvoice.getInvoicestatuscode() ) );
        ınvoice.setBoxType( boxTypeMapper.boxtypeToDto( veininvoice.getBoxtype() ) );
        ınvoice.setPartner( veinpartnerMapper.veinpartnerToDto( veininvoice.getVeinpartner() ) );
        ınvoice.setInvoiceNr( veininvoice.getInvoiceNr() );
        ınvoice.setIsarchive( veininvoice.getIsarchive() );
        ınvoice.setUblversionid( veininvoice.getUblversionid() );
        ınvoice.setCustomizationid( veininvoice.getCustomizationid() );
        ınvoice.setCopyindicator( veininvoice.getCopyindicator() );
        ınvoice.setIssuedate( localDateMapper.issueDateToCalendar( veininvoice.getIssuedate() ) );
        ınvoice.setIssuetime( veininvoice.getIssuetime() );
        ınvoice.setServicetypecode( veininvoice.getServicetypecode() );
        ınvoice.setNote( veininvoice.getNote() );
        ınvoice.setCurrencycode( veininvoice.getCurrencycode() );
        ınvoice.setLinecountnumeric( veininvoice.getLinecountnumeric() );
        ınvoice.setIsactive( veininvoice.getIsactive() );
        ınvoice.setSenderLabel( senderLabelMapper.senderLabeltoDto( veininvoice.getSenderLabel() ) );
        ınvoice.setPostboxLabel( postboxLabelMapper.postboxLabelToDto( veininvoice.getPostboxLabel() ) );
        ınvoice.setId( veininvoice.getId() );
        ınvoice.setUuid( veininvoice.getUuid() );

        return ınvoice;
    }

如您所见,变量名称创建为 ı 而不是 i。如果我尝试部署或制作模块。它失败了,类中的所有 ı 字符都变为“?” 喜欢以下。.

  @Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2016-09-05T16:39:20+0300",
    comments = "version: 1.0.0.Final, compiler: javac, environment: Java 1.8.0_74 (Oracle Corporation)"
)
public class VeininvoiceMapperImpl implements VeininvoiceMapper {

    private final LocalDateMapper localDateMapper = Mappers.getMapper( LocalDateMapper.class );
    private final BoxTypeMapper boxTypeMapper = Mappers.getMapper( BoxTypeMapper.class );
    private final InvoiceStatusCodeMapper ?nvoiceStatusCodeMapper = Mappers.getMapper( InvoiceStatusCodeMapper.class );
    private final SenderLabelMapper senderLabelMapper = Mappers.getMapper( SenderLabelMapper.class );
    private final PostboxLabelMapper postboxLabelMapper = Mappers.getMapper( PostboxLabelMapper.class );
    private final VeinpartnerMapper veinpartnerMapper = Mappers.getMapper( VeinpartnerMapper.class );

    @Override
    public Invoice veininvoiceToDto(Veininvoice veininvoice) {
        if ( veininvoice == null ) {
            return null;
        }

        Invoice ?nvoice = new Invoice();

        ?nvoice.setInvoiceStatusCode( ?nvoiceStatusCodeMapper.statusToDto( veininvoice.getInvoicestatuscode() ) );
        ?nvoice.setBoxType( boxTypeMapper.boxtypeToDto( veininvoice.getBoxtype() ) );
        ?nvoice.setPartner( veinpartnerMapper.veinpartnerToDto( veininvoice.getVeinpartner() ) );

我尝试将文件和整个项目的编码设置为 UTF-8(设置 -> 文件编码)。但它没有用。

第一个场景的 Maven 看起来像这样。

 ...
   <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-jdk8</artifactId>
            <version>${mapstruct.version}</version>
        </dependency>

        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-processor</artifactId>
            <version>${mapstruct.version}</version>
            <scope>provided</scope>
        </dependency>
      ...

<plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
           <version>3.5.1</version>
                <configuration>

                    <source>1.8</source> <!-- or higher, depending on your project -->
                    <target>1.8</target> <!-- or higher, depending on your project -->
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

然后我将Maven配置更改为以下。我设法用 i 而不是 ı 生成映射器类。但是在 make 模块上它失败并且类中的所有 i 字符都更改为?。

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <fork>true</fork>
                    <compilerArgs>
                        <arg>-J-Duser.language=en_us</arg>
                        <arg>-J-Dfile.encoding=UTF-8</arg>
                    </compilerArgs>
                    <source>1.8</source> <!-- or higher, depending on your project -->
                    <target>1.8</target> <!-- or higher, depending on your project -->
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <!--<proc>none</proc> &lt;!&ndash; disable annotation processing to avoid duplicating maven-processor-plugin output &ndash;&gt;-->
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>

更有趣的是,为了测试它,我创建了一个示例项目,其中仅包含映射器依赖项以及一个对象和 DTO(ITestObject)。我把它给了我的同事。他的 Java 和 Intellij 版本完全相同,并且还在他的笔记本电脑上安装了 windows 10 土耳其语。我们将 -J-Dfile.encoding=UTF-8 更改为 -J-Dfile.encoding=windows-1254。构建成功后,他制作的模块没有任何问题。文件没有损坏。以防万一重新编译模块,他也像我一样损坏了 Mapper 文件。但是使用相同的配置我无法在 Maven 中构建访问后成功地制作模块。我也尝试设置 MAVEN_OPTS

-Dfile.encoding=UTF-8 -Duser.country=TR -Duser.language=es -Duser.variant=Traditional_WIN

但不幸的是它没有工作。我认为,问题在某种程度上与 IntelliJ 的操作系统有关。我正在使用 IDEA 2016.2.3、Maven 3.3.9。有人知道它为什么会发生或它可能与什么有关吗?提前致谢。

4

1 回答 1

0

我认为原始的 Java 源代码是 Latin-3。

编辑器和编译器必须使用相同的编码。原则上建议更改为 UTF-8,让我们看看。

  • 在测试项目中尝试一下。
  • 有一个外部编辑器来检查编码,如 Notepad++ 或 JEdit。
  • 将编码更改为 UTF-8(POM,可能在其他地方)
  • 离开 IDE
  • 检查编码是否自动转换为 UTF-8
  • 将所有源转换为 UTF-8。
  • 启动 IDE
  • 做一个干净的,建立一切。

然后它可能不起作用。-Dfile.encoding=UTF-8for maven 是正确的属性,但不是必需的

<encoding>${project.build.sourceEncoding}</encoding>

是决定性的。检查那个project.build.sourceEncoding=UTF-8

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
于 2016-09-05T14:32:15.890 回答