Spring boot中@Entity和@Table之间的区别。我们两者都需要吗?

Mus*_*afa 8 java spring spring-annotations

我们需要模型类的两个注释吗?@Entity 和 @Table 有什么区别

@Entity
@Table(name = "widget") // do we need this??
public class WidgetEntity {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  private String clientName;
}
Run Code Online (Sandbox Code Playgroud)

小智 4

您需要 @Entity,但 @Table 是一个可选注释,您可以覆盖默认表名称、模式名称等。