类型 ClassName 的 getId() 方法未定义

Pan*_*nks 1 java spring hibernate spring-boot

我正在学习Spring boot,遇到了一个问题。我创建了一个费用类,如下所示:

    @AllArgsConstructor
@NoArgsConstructor
@Entity
@Data
@Table(name="expense")
public class Expense {
    @Id
    private Long id;

    private Instant expensedate;

    private String description;

    private String location;

    @ManyToOne
    private Category category;

    @JsonIgnore
    @ManyToOne
    private User user;
}
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试创建一个控制器来添加/删除费用对象。以下方法用于创建费用对象:

@PostMapping("/expenses")
ResponseEntity<Expense> createExpense(@Valid @RequestBody Expense expense) throws URISyntaxException{
    Expense result = expenseRepository.save(expense);
    return ResponseEntity.created(new URI("/api/expense" + result.getId())).body(result);
}
Run Code Online (Sandbox Code Playgroud)

但在此方法中我收到以下错误:

Expanse 类型的 getId() 方法未定义

Gui*_*elo 5

你的IDE安装了lombok插件了吗?

如果您使用的是 Eclipse:

龙目岛下载页面

如果您使用 Intellij,请在那里找到该插件。