簡體   English   中英

IDEA上Mapstruct中生成的源映射器的編碼問題

[英]Encoding issue for generated source mapper in Mapstruct on IDEA

我正在使用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配置更改為以下內容。 我設法與我相反生成了映射器類。 但是在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>

更有趣的是,為了對其進行測試,我創建了一個僅具有映射器依賴項以及Object和DTO(ITestObject)的示例項目。 我把它給了我的同事。 他具有與Java和Intellij完全相同的版本,並且還在筆記本電腦上安裝了Windows 10 Turkish。 我們將-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。 有人知道為什么會發生或與之相關嗎? 提前致謝。

我認為原始的Java來源是Latin-3。

編輯器和編譯器必須使用相同的編碼。 原則上建議對UTF-8進行更改,讓我們來看一下。

  • 在測試項目中全部嘗試。
  • 使用外部編輯器檢查諸如Notepad ++或JEdit之類的編碼。
  • 將編碼更改為UTF-8(POM,可能在其他地方)
  • 離開IDE
  • 檢查編碼沒有自動轉換為UTF-8
  • 將所有源轉換為UTF-8。
  • 啟動IDE
  • 做一個清潔,建立所有。

然后它可能無法正常工作。 Maven的-Dfile.encoding=UTF-8是正確的屬性,但不是必需的

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM