gpt4 book ai didi

java - 为什么@Table注解在spring的CRUD操作中是可选的

转载 作者:行者123 更新时间:2023-12-02 09:49:02 32 4
gpt4 key购买 nike

我是 spring 和 spring-boot 的新手,在学习 Spring CRUD 时,我正在阅读不同的文章,并且看到了这些内容。

"And why @Entity annotation is mandatory? … well, it is the way how JPA is designed. When you create a new entity you have to do at least two things annotated it with @Entity create an id field and annotate it with @Id Anything else is optional, for example, the table name is derived from entity class name (and therefore @Table annotation can be optional), table’s columns are derived from entities variables (and therefore @Column annotation can be optional), and so on …"

所以我的问题是,如果我们不提供@Table注释和@Column注释,Spring将如何将表及其列名 fork 。

最佳答案

正如您在 Spring Boot 的上下文中提出的问题一样。有两个选项决定命名策略:

spring.jpa.hibernate.naming.implicit-strategy

当我们没有在实体定义中明确提供表名和列名时,此选项用于确定名称

通常默认为:ImplicitNamingStrategyJpaCompliantImpl

更多 implementations .

spring.jpa.hibernate.naming.physical-strategy

这是一个更加可定制、可插入的策略契约,用于应用数据库对象名称的物理命名规则。

默认情况下,使用 SpringPhysicalNamingStrategy,其中所有点驼峰式大小写都替换为下划线。此外,表名称以小写形式生成。

关于java - 为什么@Table注解在spring的CRUD操作中是可选的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56454871/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com