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() 方法未定义
| 归档时间: |
|
| 查看次数: |
4657 次 |
| 最近记录: |