Visual Studio Code - Java - Lombok - 该方法未针对该类型进行定义
2022-09-01 13:33:33
我下载了以下项目并将其导入:Visual Studio Code
https://github.com/oktadeveloper/okta-spring-boot-2-angular-5-example
我在调用时对以下类有问题:.car.getName()
其中内容是:
酷车控制器.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
谢谢!