当前位置: 首页 > news >正文

使用Lombok无法生成Getter()与Setter()和toString()方法的解决方案

问题:在字节码文件中无法生成Getter和Setter方法

在检查实体类中有@Data和@NoArgsConstructor以及@AllArgsConstructor后

1.在IDEA中设置默认使用注解

2.删除build中的lombok

3.删除lombok中的optional的true这一句,并自己指定版本

XML
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.itheima</groupId>
    <artifactId>day22-mybatis</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>day22-mybatis</name>
    <description>day22-mybatis</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
<!--        MyBatis依赖-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.4</version>
        </dependency>

<!--        MySQL驱动依赖,新版-->
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
<!--        Lombok依赖 ,自动生成Getter和Setter方法-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.36</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter-test</artifactId>
            <version>3.0.4</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

注意:在SpringBoot中自己导入lombok

相关文章:

  • RocketMQ 中 DefaultMessageStore 的 AllocateMappedFileService 属性详解
  • 【Linux】Linux 权限:数字背后的神秘 “门禁卡” 系统
  • 剖析Spring中的设计模式(一) | 工厂观察者
  • 【零基础玩转多模态AI:Gemma3 27B开源视觉模型本地部署与远程访问】
  • 全星APQP软件:为用户提供高效、合规、便捷的研发管理体验
  • HDLBIT知识点
  • 探索 Vue 3 响应式系统:原理与实践
  • 蓝桥杯电子赛_E2PROM(AT24C02)
  • Agent 2 Agent VS MCP
  • 【C++】深拷贝与浅拷贝
  • GitHub 趋势日报 (2025年04月08日)
  • C语言精讲-12
  • 【Linux】基础开发工具
  • 八大可商用桌面客户端应用开发框架深度指南-优雅草卓伊凡
  • 操作系统基础:05 系统调用实现
  • playwright 教程高级篇:掌握网页自动化与验证码处理等关键技术详解
  • [数据结构]排序 --2
  • 【C++】C++的引用
  • 在 Ubuntu 下通过 Docker 部署 Caddy 服务器
  • C++双链表介绍及实现
  • 东方红资管官宣:41岁原国信资管董事长成飞出任新总经理
  • 聆听百年唐调正声:唐文治王蘧常吟诵传习的背后
  • 中国一重集团有限公司副总经理陆文俊被查
  • “降息潮”延续!存款利率全面迈向“1时代”
  • 47本笔记、2341场讲座,一位普通上海老人的阅读史
  • 逆境之上,万物生长