Visual Studio代码-Java-龙目岛-该类型的方法未定义

dav*_*esp 4 java spring-mvc lombok visual-studio-code java-annotations

我下载了以下项目并将其导入到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/d5c959162ed0f862a5dceb93f5957f92e052e06e062/server/src/main/java/com/okta/developer/demo/CoolCarController.java

内容是:

CoolCarController.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");
    }
}
Run Code Online (Sandbox Code Playgroud)

这也是以下内容:

汽车.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;
}
Run Code Online (Sandbox Code Playgroud)

正如您在下图所看到的,我得到了错误:

[Java] The method getName() is undefined for the type Car
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我认为Visual Studio Code不了解该软件包:lombok

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

谢谢!

小智 24

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

按下Command + shift + P并执行:

Java: Clean Java language server workspace
Run Code Online (Sandbox Code Playgroud)

  • 这应该在 VSCode 扩展的安装指令中说明。 (2认同)

dav*_*esp 9

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

  • 它对我没有用。我安装了扩展程序,它整理了编辑器的Intellisense,但没有整理出编译本身。尝试从VSCode中运行代码时,出现了“生成失败,您要继续吗?”错误消息。如果我选择_“继续” _,则出现错误**未解决的编译问题**。多个构造函数和方法未定义。 (3认同)