• 使用lombok 注解Java类


    环境信息:

    IDEA  2016.2.4

    Maven 3

    JDK 1.8

    Maven工程配置:

    <properties>   
        <lombok.version>1.16.16</lombok.version>
        <lombok.plugin.version>1.16.16.0</lombok.plugin.version>
    </properties>
        <dependencies>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
                <version>2.8.2</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
                <version>2.8.2</version>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
     <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok-maven-plugin</artifactId>
                        <version>${lombok.plugin.version}</version>
                        <executions>
                            <execution>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>delombok</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>

    安装lombok插件: 

    1. 下载 https://plugins.jetbrains.com/plugin/6317-lombok-plugin

    2.  Setting -> plugins ->install plugin from disk 

    3.  Setting->Build,Exe... -> Compiler->Annotation Processors -> 勾选enable annotation processing

    遇到的问题:

    1.  The parameters 'encoding' for goal org.projectlombok:lombok-maven-plugin:1.16.16.0:delombok are missing or invalid

    根据 , 缺少encoding参数 在pom中添加如下属性:

            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    2. 添加@Data注解后,根据注解生成的方法没有在outline中显示, 以及无法在代码编辑是resolve注解生成的方法

    解决: 添加lombok-plugin

    参考: https://stackoverflow.com/questions/41161076/adding-lombok-plugin-to-intellij-project 

  • 相关阅读:
    JQuery学习四(过滤选择器)
    JQuery学习三(隐式迭代和节点遍历)
    JQuery学习二(获取元素控件并控制)
    JQuery学习一
    Dom中select练习
    DOM动态操纵控件案例
    DOM学习控件定位和案例
    DOM案例五星评分控件
    DOM动态增加控件
    DOM用TagName操作标签
  • 原文地址:https://www.cnblogs.com/ridox/p/7233205.html
Copyright © 2020-2023  润新知