Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 51 章 Spring Data with MySQL

目录

51.1. 选择数据库表引擎
51.2. 声明实体
51.2.1. @Entity 声明实体
51.2.2. @Table 定义表名
51.2.3. @Id 定义主键
51.2.4. @Column 定义字段:
51.2.5. 非数据库字段
51.2.6. @Lob 注解属性将被持久化为 Blog 或 Clob 类型
51.2.7. @NotNull 不能为空声明
51.2.8. @Temporal 日期定义
51.2.9. 创建日期
51.2.10. @DateTimeFormat 处理日期时间格式
51.2.11. Enum 枚举数据类型
51.2.12. SET 数据结构
51.2.13. JSON 数据类型
51.2.14. 嵌入
51.2.15. @JsonIgnore
51.2.16. @EnableJpaAuditing 开启 JPA 审计功能
51.2.17. 注释 @Comment
51.2.18. @Pattern 数据匹配
51.2.19. 实体继承
51.3. 映射集合属性
51.3.1. List 集合
51.3.2. 数组集合
51.3.3. Map 集合
51.3.4. Set 集合
51.3.5. 外键名称
51.3.6. 集合表子查询
51.4. 外键
51.4.1. @JoinColumn
51.4.2. @OneToOne
51.4.3. OneToMany 一对多
51.4.4. ManyToMany 多对多
51.4.5. 外键级联删除
51.4.6. 外键级联操作
51.4.7. @JoinTable
51.4.8. @OrderBy
51.4.9. @JsonIgnoreProperties
51.5. 索引
51.5.1. 普通索引
51.5.2. 组合索引
51.5.3. 唯一索引
51.6. Repository
51.6.1. JpaRepository
51.6.2. CrudRepository
51.6.3. PagingAndSortingRepository
51.6.4. findByXXX
51.6.5. count 操作
51.6.6. delete 删除操作
51.6.7. IsNull
51.6.8. In/NotIn
51.6.9. TRUE / FALSE
51.6.10. OrderBy
51.6.11. GreaterThan
51.6.12. Sort 排序操作操作
51.6.13. Pageable 翻页操作
51.6.14. @DynamicInsert 与 @DynamicUpdate
51.6.15. 继承已存在的 Repository
51.6.16. 自定义返回字段
51.7. TransactionTemplate
51.8. JPQL @Query
51.8.1. @Modifying 更新/删除
51.8.2. 事务 @Transactional
51.8.3. 参数传递
51.8.4. 原生 SQL 操作
51.8.5. @Query 与 Pageagble
51.8.6. 返回指定字段
51.8.7. 返回指定的模型
51.8.8. @Query 与 @ManyToOne
51.8.9. Collection
51.8.10. Sort
51.8.11. 更新数据,返回值
51.8.12. 锁 @Lock
51.9. FAQ 常见问题
51.9.1. Could not write JSON: failed to lazily initialize a collection of role
51.9.2. Query did not return a unique result: 2 results were returned
51.9.3. Executing an update/delete query

51.1. 选择数据库表引擎

正常创建表会使用数据库默认引擎,有时数据库默认引擎并不是我们需要的,通过下面配置可以指定表引擎

			
# Spring boot 1.x.x
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect

# Spring boot 2.0.2
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect