Visual Studio Code - Java - Lombok - 该方法未针对该类型进行定义

我下载了以下项目并将其导入:Visual Studio Code

https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example

我在调用时对以下类有问题:.car.getName()

https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example/blob/d5c959162ed0f862a5dceb93f5957f92e052e062/server/src/main/java/com/okta/developer/demo/CoolCarController.java

其中内容是:

酷车控制器.java

package com.okta.developer.demo;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.stream.Collectors;

@RestController
class CoolCarController {
    private CarRepository repository;

    public CoolCarController(CarRepository repository) {
        this.repository = repository;
    }

    @GetMapping("/cool-cars")
    @CrossOrigin(origins = "http://localhost:4200")
    public Collection<Car> coolCars() {
        return repository.findAll().stream()
                .filter(this::isCool)
                .collect(Collectors.toList());
    }

    private boolean isCool(Car car) {
        return !car.getName().equals("AMC Gremlin") &&
                !car.getName().equals("Triumph Stag") &&
                !car.getName().equals("Ford Pinto") &&
                !car.getName().equals("Yugo GV");
    }
}

这里也是内容:

汽车.java

package com.okta.developer.demo;

import lombok.*;

import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.Entity;

@Entity
@Getter @Setter
@NoArgsConstructor
@ToString @EqualsAndHashCode
public class Car {
    @Id @GeneratedValue
    private Long id;
    private @NonNull String name;
}

正如您在下图中看到的,我遇到了错误:

[Java] The method getName() is undefined for the type Car

enter image description here

我认为不理解包装:.Visual Studio Codelombok

关于我如何理解该软件包的任何想法?Visual Studio Code

谢谢!


答案 1

好的,安装扩展:(gabrielbb.vscode-lombok)做到了。Lombok Annotations Support for VS Code


答案 2

如果您的项目在安装此插件之前加载,则可以在 vscode 中运行此命令以重新加载项目。Lombok Annotations Support for VS Code

按下并执行:Command + shift + P

Java: Clean Java language server workspace

推荐