springboot JPA 取消小驼峰到下划线映射,JPA取值部分字段为NULL的问题

springboot JPA 取消小驼峰到下划线映射,JPA取值部分字段为NULL的问题

这种问题多半是因为数据库字段是小驼峰命名,虽然实体字段和数据库字段一致,但是 JPA 的生成的sql语句还是把小驼峰转化为 下划线了所以查不到;

#错误生成sql
select `appointmen0_`.id as id1_0_, appointmen0_.appointment_code as appointm2_0_, appointmen0_.appointment_time as appointm3_0_, appointmen0_.arrival_time as arrival_4_0_
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot 默认使用的是 Hibernate 作为 JPA 的实现。在 Spring Boot 中,配置 JPA 驼峰命名规则需要进行以下步骤: 1. 在应用的配置文件(application.properties 或 application.yml)中,添加以下配置: ``` spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy ``` 这样配置就会启用 Hibernate 的物理命名策略,该策略会自动将数据库的列名转换为驼峰命名。 2. 如果需要对实体类的属性进行特殊处理,可以使用 Hibernate 的 @Column 注解的 name 属性进行手动配置,例如: ```java @Entity public class User { @Column(name = "first_name") private String firstName; //... } ``` 这样可以将数据库列名设置为 "first_name",而不是自动转换为驼峰命名规则。 总结起来,通过在配置文件中设置 Hibernate 的物理命名策略,以及使用 @Column 注解来手动配置特殊的列名,可以实现在 Spring Boot 中对 JPA 进行驼峰命名的配置。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [SpringBoot教程(十二) | SpringBoot集成JPA](https://blog.csdn.net/lsqingfeng/article/details/122854090)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [2.springboot配置jpa](https://blog.csdn.net/qq_44959735/article/details/131576343)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值