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

部分 VI. Spring Data

目录

71. EntityManager
72. Spring Data with JdbcTemplate
72.1. execute
72.2. queryForInt
72.3. queryForLong
72.4. queryForObject
72.4.1. 返回整形与字符型
72.4.2. 查询 Double 类型数据库
72.4.3. 返回日期
72.4.4. 返回结果集
72.4.5. 通过 "?" 向SQL传递参数
72.4.6. RowMapper 记录映射
72.5. queryForList
72.5.1. Iterator 用法
72.5.2. for 循环
72.5.3. forEach 用法
72.6. queryForMap
72.7. query
72.7.1. ResultSet
72.7.2. ResultSetExtractor
72.7.3. RowMapper
72.8. queryForRowSet
72.9. update
72.10. MapSqlParameterSource
72.11. 实例参考
72.11.1. 参数传递技巧
73. Spring Data with MySQL
73.1. 选择数据库表引擎
73.2. 声明实体
73.2.1. @Entity 声明实体
73.2.2. @Table 定义表名
73.2.3. @Id 定义主键
73.2.4. @Column 定义字段:
73.2.5. 非数据库字段
73.2.6. @Lob 注解属性将被持久化为 Blog 或 Clob 类型
73.2.7. @NotNull 不能为空声明
73.2.8. @Temporal 日期定义
73.2.9. 创建日期
73.2.10. @DateTimeFormat 处理日期时间格式
73.2.11. Enum 枚举数据类型
73.2.12. SET 数据结构
73.2.13. JSON 数据类型
73.2.14. 嵌入
73.2.15. @JsonIgnore
73.2.16. @EnableJpaAuditing 开启 JPA 审计功能
73.2.17. 注释 @Comment
73.2.18. @Pattern 数据匹配
73.2.19. 实体继承
73.3. 映射集合属性
73.3.1. List 集合
73.3.2. 数组集合
73.3.3. Map 集合
73.3.4. Set 集合
73.3.5. 外键名称
73.3.6. 集合表子查询
73.4. 外键
73.4.1. @JoinColumn
73.4.2. @OneToOne
73.4.3. OneToMany 一对多
73.4.4. ManyToMany 多对多
73.4.5. 外键级联删除
73.4.6. 外键级联操作
73.4.7. @JoinTable
73.4.8. @OrderBy
73.4.9. @JsonIgnoreProperties
73.5. 索引
73.5.1. 普通索引
73.5.2. 组合索引
73.5.3. 唯一索引
73.6. Repository
73.6.1. JpaRepository
73.6.2. CrudRepository
73.6.3. PagingAndSortingRepository
73.6.4. findByXXX
73.6.5. count 操作
73.6.6. delete 删除操作
73.6.7. IsNull
73.6.8. In/NotIn
73.6.9. TRUE / FALSE
73.6.10. OrderBy
73.6.11. GreaterThan
73.6.12. Sort 排序操作操作
73.6.13. Pageable 翻页操作
73.6.14. @DynamicInsert 与 @DynamicUpdate
73.6.15. 继承已存在的 Repository
73.6.16. 自定义返回字段
73.7. TransactionTemplate
73.8. JPQL @Query
73.8.1. @Modifying 更新/删除
73.8.2. 参数传递
73.8.3. 原生 SQL 操作
73.8.4. @Query 与 Pageagble
73.8.5. 返回指定字段
73.8.6. 返回指定的模型
73.8.7. @Query 与 @ManyToOne
73.8.8. Collection
73.8.9. Sort
73.8.10. 更新数据,返回值
73.8.11. 锁 @Lock
73.9. 事务 @Transactional
73.9.1. save() 不需要开启 @Transactional
73.9.2. SERIALIZABLE
73.9.3. readOnly
73.9.4. 删除更新需要 @Transactional 注解
73.9.5. 回滚操作
73.9.6. private、default、protected 和 final 不支持事物
73.9.7. Service 注意事项
73.9.8. 需要 @Service 注解配合使用
73.9.9.
73.10. FAQ 常见问题
73.10.1. Could not write JSON: failed to lazily initialize a collection of role
73.10.2. Query did not return a unique result: 2 results were returned
73.10.3. Executing an update/delete query
74. Spring Data with Redis
74.1. 集成 Redis XML 方式
74.1.1. pom.xml
74.1.2. springframework-servlet.xml
74.1.3. Controller
74.1.4. index.jsp
74.1.5. 测试
74.2. 通过构造方法实例化 Redis
74.3. stringRedisTemplate 基本用法
74.4. RedisTemplate
74.4.1. 设置缓存时间
74.4.2. increment
74.4.3. 删除 key
74.4.4. 对象存储
74.4.5. 获取过期时间
74.4.6. 过期时间未执行
74.5. ValueOperations
74.5.1. 字符串截取
74.5.2. 追加字符串
74.5.3. 设置键的字符串值并返回其旧值
74.5.4. 返回字符串长度
74.5.5. 如果key不存便缓存。
74.5.6. 缓存多个值 /获取多个值 multiSet / multiGet
74.5.7. setBit / getBit 二进制位操作
74.6. 列表操作
74.6.1. rightPush
74.6.2. rightPushAll
74.6.3. rightPushIfPresent
74.6.4. leftPush
74.6.5. leftPushAll
74.6.6. range
74.7. SetOperations 数据类型
74.7.1. 返回集合中的所有成员
74.7.2. 取出一个成员
74.7.3. 随机获取无序集合中的一个元素
74.7.4. 随机获取 n 个成员(存在重复数据)
74.7.5. 随机获取 n 个不重复成员
74.7.6. 在两个 SET 间移动数据
74.7.7. 成员删除
74.7.8. 返回集合数量
74.7.9. 判断元素是否在集合成员中
74.7.10. 对比两个集合求交集
74.7.11. 对比两个集合求交集,然后存储到新的 key 中
74.7.12. 合并两个集合,并去处重复数据
74.7.13. 合并两个集合去重复后保存到新的 key 中
74.7.14. 计算两个合集的差集
74.7.15. 计算两个合集的差集,然后保存到新的 key 中
74.7.16. 遍历 SET 集合
74.8. ZSetOperations 有序的 set 集合
74.9. HashOperations
74.9.1. put
74.9.2. putAll
74.9.3. 从键中的哈希获取给定hashKey的值
74.9.4. delete
74.9.5. 确定哈希hashKey是否存在
74.9.6. 从哈希中获取指定的多个 hashKey 的值
74.9.7. 只有hashKey不存在时才能添加值
74.9.8. 获取整个Hash
74.9.9. 获取所有key
74.9.10. 通过 hashKey 获取所有值
74.9.11. 值加法操作
74.9.12. 遍历 Hash 表
74.10. 存储 Json 对象
74.10.1. 集成 RedisTemplate 定义新类 JsonRedisTemplate
74.10.2. 配置 Redis
74.10.3. 测试
74.11. Spring Data Redis - Repository Examples
74.11.1. @EnableRedisRepositories 启动 Redis 仓库
74.11.2. 定义 Domain 类
74.11.3. Repository 接口
74.11.4. 测试代码
74.12. CacheService
74.13. FAQ
74.13.1. Spring Data Redis
75. Spring Data with MongoDB
75.1. Example Spring Data MongoDB
75.1.1. pom.xml
75.1.2. springframework-servlet.xml
75.1.3. POJO
75.1.4. Controller
75.1.5. 查看测试结果
75.1.6. 条件查询
75.2. MongoDB 多数据源
75.2.1. Maven
75.2.2. Application 禁止自动配置 MongoDB
75.2.3. application.properties 新增配置项
75.2.4. MongoDB 配置类
75.2.5. 创建 Document 关系映射类
75.2.6. 测试控制器
75.2.7. 测试
75.3. @Document
75.3.1. 指定表名
75.3.2. @Id
75.3.3. @Version
75.3.4. @Field 定义字段名
75.3.5. @Indexed
75.3.6. @CompoundIndex 复合索引
75.3.7. @TextIndexed
75.3.8. @GeoSpatialIndex 地理位置索引
75.3.9. @Transient 丢弃数据,不存到 mongodb
75.3.10. @DBRef 做外外键引用
75.3.11. @DateTimeFormat
75.3.12. @NumberFormat
75.3.13. 在 @Document 中使用 Enum 类型
75.3.14. 在 @Document 中定义数据结构 List/Map
75.3.15. GeoJson 数据类型
75.4. MongoRepository
75.4.1. 扫描仓库接口
75.4.2. findAll()
75.4.3. deleteAll()
75.4.4. save()
75.4.5. count()
75.4.6. exists() 判断是否存在
75.4.7. existsById()
75.4.8. findByXXXX
75.4.9. findAll with OrderBy
75.4.10. findAll with Sort
75.4.11. FindAll with Pageable
75.4.12. StartingWith 和 EndingWith
75.4.13. Between
75.4.14. Before / After
75.4.15. @Query
75.5. mongoTemplate
75.5.1. Save 保存
75.5.2. Insert
75.5.3. updateFirst 修改符合条件第一条记录
75.5.4. updateMulti 修改符合条件的所有
75.5.5. 查找并保存
75.5.6. upsert - 修改符合条件时如果不存在则添加
75.5.7. 删除
75.5.8. 查找一条数据
75.5.9. 查找所有数据
75.5.10. Query
75.5.11. Criteria
75.5.12. Update
75.5.13. BasicUpdate
75.5.14. Sort
75.5.15. Query + PageRequest
75.5.16. newAggregation
75.5.17. 创建索引
75.5.18. 子对象操作
75.6. GeoJson 反序列化
75.7. FAQ
75.7.1. location object expected, location array not in correct format; nested exception is com.mongodb.MongoWriteException: location object expected, location array not in correct format
76. Spring Data with Elasticsearch
76.1. 内嵌 Elasticsearch
76.1.1. Maven
76.1.2. src/main/resources/application.properties
76.1.3. Domain Class
76.1.4. ElasticsearchRepository
76.1.5. SearchRestController
76.1.6. 测试
76.2. 集群模式
76.3. Document
76.4. Elasticsearch 删除操作
76.5. FAQ
76.5.1. java.lang.IllegalStateException: Received message from unsupported version: [2.0.0] minimal compatible version is: [5.0.0]
77. Spring boot with Data restful
77.1. Maven
78. Apache ShardingSphere
78.1. 微服务集群环境,雪花算法出现重复ID
78.1.1. 方案一、配置实现
78.1.2. 方案二、代码实现