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

部分 III. Spring Data

目录

46. EntityManager
47. Spring Data with JdbcTemplate
47.1. execute
47.2. queryForInt
47.3. queryForLong
47.4. queryForObject
47.4.1. 返回整形与字符型
47.4.2. 查询 Double 类型数据库
47.4.3. 返回日期
47.4.4. 返回结果集
47.4.5. 通过 "?" 向SQL传递参数
47.4.6. RowMapper 记录映射
47.5. queryForList
47.5.1. Iterator 用法
47.5.2. for 循环
47.5.3. forEach 用法
47.6. queryForMap
47.7. query
47.7.1. ResultSet
47.7.2. ResultSetExtractor
47.7.3. RowMapper
47.8. queryForRowSet
47.9. update
47.10. MapSqlParameterSource
47.11. 实例参考
47.11.1. 参数传递技巧
48. Spring Data with MySQL
48.1. 选择数据库表引擎
48.2. 声明实体
48.2.1. @Entity 声明实体
48.2.2. @Table 定义表名
48.2.3. @Id 定义主键
48.2.4. @Column 定义字段:
48.2.5. 非数据库字段
48.2.6. @Lob 注解属性将被持久化为 Blog 或 Clob 类型
48.2.7. @NotNull 不能为空声明
48.2.8. @Temporal 日期定义
48.2.9. 创建日期
48.2.10. @DateTimeFormat 处理日期时间格式
48.2.11. Enum 枚举数据类型
48.2.12. SET 数据结构
48.2.13. JSON 数据类型
48.2.14. 嵌入
48.2.15. @JsonIgnore
48.2.16. @EnableJpaAuditing 开启 JPA 审计功能
48.2.17. 注释 @Comment
48.2.18. @Pattern 数据匹配
48.2.19. 实体继承
48.3. 映射集合属性
48.3.1. List 集合
48.3.2. 数组集合
48.3.3. Map 集合
48.3.4. Set 集合
48.3.5. 外键名称
48.3.6. 集合表子查询
48.4. 外键
48.4.1. @JoinColumn
48.4.2. @OneToOne
48.4.3. OneToMany 一对多
48.4.4. ManyToMany 多对多
48.4.5. 外键级联删除
48.4.6. 外键级联操作
48.4.7. @JoinTable
48.4.8. @OrderBy
48.4.9. @JsonIgnoreProperties
48.5. 索引
48.5.1. 普通索引
48.5.2. 组合索引
48.5.3. 唯一索引
48.6. Repository
48.6.1. JpaRepository
48.6.2. CrudRepository
48.6.3. PagingAndSortingRepository
48.6.4. findByXXX
48.6.5. count 操作
48.6.6. delete 删除操作
48.6.7. IsNull
48.6.8. In/NotIn
48.6.9. TRUE / FALSE
48.6.10. OrderBy
48.6.11. GreaterThan
48.6.12. Sort 排序操作操作
48.6.13. Pageable 翻页操作
48.6.14. @DynamicInsert 与 @DynamicUpdate
48.6.15. 继承已存在的 Repository
48.6.16. 自定义返回字段
48.7. TransactionTemplate
48.8. JPQL @Query
48.8.1. @Modifying 更新/删除
48.8.2. 参数传递
48.8.3. 原生 SQL 操作
48.8.4. @Query 与 Pageagble
48.8.5. 返回指定字段
48.8.6. 返回指定的模型
48.8.7. @Query 与 @ManyToOne
48.8.8. Collection
48.8.9. Sort
48.8.10. 更新数据,返回值
48.8.11. 锁 @Lock
48.9. 事务 @Transactional
48.9.1. save() 不需要开启 @Transactional
48.9.2. SERIALIZABLE
48.9.3. readOnly
48.9.4. 删除更新需要 @Transactional 注解
48.9.5. 回滚操作
48.9.6. private、default、protected 和 final 不支持事物
48.9.7. Service 注意事项
48.9.8. 需要 @Service 注解配合使用
48.9.9.
48.10. FAQ 常见问题
48.10.1. Could not write JSON: failed to lazily initialize a collection of role
48.10.2. Query did not return a unique result: 2 results were returned
48.10.3. Executing an update/delete query
49. Spring Data with Redis
49.1. 集成 Redis XML 方式
49.1.1. pom.xml
49.1.2. springframework-servlet.xml
49.1.3. Controller
49.1.4. index.jsp
49.1.5. 测试
49.2. 通过构造方法实例化 Redis
49.3. stringRedisTemplate 基本用法
49.4. RedisTemplate
49.4.1. 设置缓存时间
49.4.2. increment
49.4.3. 删除 key
49.4.4. 对象存储
49.4.5. 获取过期时间
49.4.6. 过期时间未执行
49.5. ValueOperations
49.5.1. 字符串截取
49.5.2. 追加字符串
49.5.3. 设置键的字符串值并返回其旧值
49.5.4. 返回字符串长度
49.5.5. 如果key不存便缓存。
49.5.6. 缓存多个值 /获取多个值 multiSet / multiGet
49.5.7. setBit / getBit 二进制位操作
49.6. 列表操作
49.6.1. rightPush
49.6.2. rightPushAll
49.6.3. rightPushIfPresent
49.6.4. leftPush
49.6.5. leftPushAll
49.6.6. range
49.7. SetOperations 数据类型
49.7.1. 返回集合中的所有成员
49.7.2. 取出一个成员
49.7.3. 随机获取无序集合中的一个元素
49.7.4. 随机获取 n 个成员(存在重复数据)
49.7.5. 随机获取 n 个不重复成员
49.7.6. 在两个 SET 间移动数据
49.7.7. 成员删除
49.7.8. 返回集合数量
49.7.9. 判断元素是否在集合成员中
49.7.10. 对比两个集合求交集
49.7.11. 对比两个集合求交集,然后存储到新的 key 中
49.7.12. 合并两个集合,并去处重复数据
49.7.13. 合并两个集合去重复后保存到新的 key 中
49.7.14. 计算两个合集的差集
49.7.15. 计算两个合集的差集,然后保存到新的 key 中
49.7.16. 遍历 SET 集合
49.8. ZSetOperations 有序的 set 集合
49.9. HashOperations
49.9.1. put
49.9.2. putAll
49.9.3. 从键中的哈希获取给定hashKey的值
49.9.4. delete
49.9.5. 确定哈希hashKey是否存在
49.9.6. 从哈希中获取指定的多个 hashKey 的值
49.9.7. 只有hashKey不存在时才能添加值
49.9.8. 获取整个Hash
49.9.9. 获取所有key
49.9.10. 通过 hashKey 获取所有值
49.9.11. 值加法操作
49.9.12. 遍历 Hash 表
49.10. 存储 Json 对象
49.10.1. 集成 RedisTemplate 定义新类 JsonRedisTemplate
49.10.2. 配置 Redis
49.10.3. 测试
49.11. Spring Data Redis - Repository Examples
49.11.1. @EnableRedisRepositories 启动 Redis 仓库
49.11.2. 定义 Domain 类
49.11.3. Repository 接口
49.11.4. 测试代码
49.12. CacheService
49.13. FAQ
49.13.1. Spring Data Redis
50. Spring Data with MongoDB
50.1. Example Spring Data MongoDB
50.1.1. pom.xml
50.1.2. springframework-servlet.xml
50.1.3. POJO
50.1.4. Controller
50.1.5. 查看测试结果
50.1.6. 条件查询
50.2. MongoDB 多数据源
50.2.1. Maven
50.2.2. Application 禁止自动配置 MongoDB
50.2.3. application.properties 新增配置项
50.2.4. MongoDB 配置类
50.2.5. 创建 Document 关系映射类
50.2.6. 测试控制器
50.2.7. 测试
50.3. @Document
50.3.1. 指定表名
50.3.2. @Id
50.3.3. @Version
50.3.4. @Field 定义字段名
50.3.5. @Indexed
50.3.6. @CompoundIndex 复合索引
50.3.7. @TextIndexed
50.3.8. @GeoSpatialIndex 地理位置索引
50.3.9. @Transient 丢弃数据,不存到 mongodb
50.3.10. @DBRef 做外外键引用
50.3.11. @DateTimeFormat
50.3.12. @NumberFormat
50.3.13. 在 @Document 中使用 Enum 类型
50.3.14. 在 @Document 中定义数据结构 List/Map
50.3.15. GeoJson 数据类型
50.4. MongoRepository
50.4.1. 扫描仓库接口
50.4.2. findAll()
50.4.3. deleteAll()
50.4.4. save()
50.4.5. count()
50.4.6. exists() 判断是否存在
50.4.7. existsById()
50.4.8. findByXXXX
50.4.9. findAll with OrderBy
50.4.10. findAll with Sort
50.4.11. FindAll with Pageable
50.4.12. StartingWith 和 EndingWith
50.4.13. Between
50.4.14. Before / After
50.4.15. @Query
50.5. mongoTemplate
50.5.1. Save 保存
50.5.2. Insert
50.5.3. updateFirst 修改符合条件第一条记录
50.5.4. updateMulti 修改符合条件的所有
50.5.5. 查找并保存
50.5.6. upsert - 修改符合条件时如果不存在则添加
50.5.7. 删除
50.5.8. 查找一条数据
50.5.9. 查找所有数据
50.5.10. Query
50.5.11. Criteria
50.5.12. Update
50.5.13. BasicUpdate
50.5.14. Sort
50.5.15. Query + PageRequest
50.5.16. newAggregation
50.5.17. 创建索引
50.5.18. 子对象操作
50.6. GeoJson 反序列化
50.7. FAQ
50.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
51. Spring Data with Elasticsearch
51.1. 内嵌 Elasticsearch
51.1.1. Maven
51.1.2. src/main/resources/application.properties
51.1.3. Domain Class
51.1.4. ElasticsearchRepository
51.1.5. SearchRestController
51.1.6. 测试
51.2. 集群模式
51.3. Document
51.4. Elasticsearch 删除操作
51.5. FAQ
51.5.1. java.lang.IllegalStateException: Received message from unsupported version: [2.0.0] minimal compatible version is: [5.0.0]
52. Spring boot with Data restful
52.1. Maven
53. Apache ShardingSphere
53.1. 微服务集群环境,雪花算法出现重复ID
53.1.1. 方案一、配置实现
53.1.2. 方案二、代码实现