初步入门
可以参考:程序猿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);