21

我下载了以下项目并将其导入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

在此处输入图像描述

我想Visual Studio Code不明白这个包:lombok.

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

谢谢!

4

2 回答 2

41

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

于 2018-07-14T00:04:59.997 回答
35

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

按下Command + shift + P并执行:

Java: Clean Java language server workspace
于 2020-09-12T00:35:24.090 回答