Spring Boot学习笔记-JPA

初步入门

可以参考:程序猿DD的这篇文章
Spring Boot中使用Spring-data-jpa让数据访问更简单、更优雅

Tips

利用自动生成jpa实体类

http://blog.csdn.net/liu_yulong/article/details/72910588
https://stackoverflow.com/questions/46892039/intellij-idea-persistence-support-for-spring-boot-project

entity代码中的字段与数据库物理字段保持一致

字段命名默认策略:

org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

entity中userAge,spring在访问的时候会变成user_age
要做到与数据库字段命名一致,需要加上以下配置

spring:
  jpa:
    hibernate:
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

repository 中 获取某一行,某个字段的值

@Query(value = "select title FROM rule WHERE appId=?1 AND level=?2", nativeQuery = true)
String getTitleByAppIdAndLevel(int appId, int level);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容