Reputation: 639
I am learning Spring boot and got stuck in a problem. I have created an Expense class as following:
@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;
}
Now I am trying to create a controller to add/delete the Expense objects. Following method is for creating Expense object:
@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);
}
But here in this method I am getting following error:
The method getId() is undefined for the type Expanse
Upvotes: 1
Views: 6611
Reputation: 25
update intellij IDEA and restart. it may take little time. and install lombok plugin.it works for me.
here , i faced the issue : https://www.youtube.com/watch?v=uNC8v-BVLRU&list=PLGRDMO4rOGcNLnW1L2vgsExTBg-VPoZHr&index=6&t=146s
Upvotes: 0
Reputation: 101
If the above methods like:
installing Lombak
restarting Eclipse
Clean/Build the project still show the error, try a forth thing:
I deleted the last character of @Data and used intellisense to put it back. Eclipse refreshed the project and the getId() was gone.
Upvotes: 0
Reputation: 199
Did You have install lombok plugin in your IDE?
If you are using Eclipse:
If you are using Intellij find the plugin there.
Upvotes: 5