zoukankan      html  css  js  c++  java
  • 更新 Spring Data JPA 之数据表名的命名规则为驼峰命名法

     

    1、版本:
      1.1 Windows 10 操作系统;
      1.2、Java Develop Kit 11;
      1.3 Spring Boot 2.3.2;

    2、我们知道 Spring Data JPA 对数据表默认的命名规则为两个单词之间以下划线分割,这个良好的命名方式是比较传统的,也是比较经典,其中有一部分原因是 SQL 对大小写不敏感所致,不过现在我们可以通过对 MySQL 进行配置,从而让驼峰命名法的字段也很美观,这样在命名规则上就与 Java 的实体类相同了,更方便编写。
      2.1、缺省情况下属性 createTime 会被 JPA 创建为字段 create_time (如果已存在则不再创建);
      2.2、驼峰命名法下属性 createTime 会被 JPA 创建为字段 createTime(如果已存在则不再创建);

    3、我们可以在 Spring 框架的配置文件 application.properties 中加入如下配置:
      spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
      spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

    4、我们也可以在 Spring 框架的配置文件 application.ymal 中加入如下配置:
      jpa:
        hibernate:
        naming:
        implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
          physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

    5、第三条和第四条是等效的,任选其一即可。

  • 相关阅读:
    Sum Root to Leaf Numbers 解答
    459. Repeated Substring Pattern
    71. Simplify Path
    89. Gray Code
    73. Set Matrix Zeroes
    297. Serialize and Deserialize Binary Tree
    449. Serialize and Deserialize BST
    451. Sort Characters By Frequency
    165. Compare Version Numbers
    447. Number of Boomerangs
  • 原文地址:https://www.cnblogs.com/hapday/p/13500277.html
Copyright © 2011-2022 走看看