正文
SpringData JPA 在解析实体类字段时驼峰自动添加下划线问题
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
参考地址:https://my.oschina.net/javamaster/blog/2246886
SpringData JPA 使用的默认命名策略是: ImprovedNamingStrategy 。用下划线转换驼峰名,如 authorId ,转换成 author_id 。这样就遇到了一个问题:实体中驼峰命名的列名转换成下划线后,在MySQL中执行时找不到字段。
解决办法:
在application.properties 添加设置
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl