2017年3月11日

自定义 Repository 方法

摘要: 为某一个 Repository 上添加自定义方法 步骤: 定义一个接口: 声明要添加的, 并自实现的方法 为所有的 Repository 都添加自实现的方法 步骤: 声明一个接口, 在该接口中声明需要自定义的方法, 且该接口需要继承 Spring Data 的 Repository. 定义 JpaR 阅读全文

posted @ 2017-03-11 23:20 airycode 阅读(1964) 评论(0) 推荐(0) 编辑

SpringData_JpaSpecificationExecutor接口

摘要: 不属于Repository体系,实现一组 JPA Criteria 查询相关的方法 Specification:封装 JPA Criteria 查询条件。通常使用匿名内部类的方式来创建该接口的对象 Specification:封装 JPA Criteria 查询条件。通常使用匿名内部类的方式来创建该 阅读全文

posted @ 2017-03-11 23:08 airycode 阅读(5816) 评论(0) 推荐(0) 编辑

SpringData_JpaRepository接口

摘要: 该接口提供了JPA的相关功能 List<T> findAll(); //查找所有实体 List<T> findAll(Sort sort); //排序、查找所有实体 List<T> save(Iterable<? extends T> entities);//保存集合 void flush();// 阅读全文

posted @ 2017-03-11 23:05 airycode 阅读(718) 评论(0) 推荐(0) 编辑

SpringData_PagingAndSortingRepository接口

摘要: 该接口提供了分页与排序功能 Iterable<T> findAll(Sort sort); //排序 Page<T> findAll(Pageable pageable); //分页查询(含排序功能 该接口提供了分页与排序功能 Iterable<T> findAll(Sort sort); //排序 阅读全文

posted @ 2017-03-11 23:02 airycode 阅读(1000) 评论(0) 推荐(0) 编辑

SpringData_CrudRepository接口

摘要: CrudRepository CrudRepository 接口提供了最基本的对实体类的添删改查操作 T save(T entity);//保存单个实体 Iterable<T> save(Iterable<? extends T> entities);//保存集合 T findOne(ID id); 阅读全文

posted @ 2017-03-11 22:38 airycode 阅读(3629) 评论(0) 推荐(0) 编辑

SpringData修改和删除操作

摘要: SpringData的查询我们已经学完了,我们现在就研究一下SpringData的修改和删除。 @Modifying 注解和事务 @Query 与 @Modifying 这两个 annotation一起声明,可定义个性化更新操作,例如只涉及某些字段更新时最为常用,示例如下: //可以通过自定义的 J 阅读全文

posted @ 2017-03-11 22:25 airycode 阅读(596) 评论(0) 推荐(0) 编辑

自定义查询语句SpringData

摘要: 虽然官方的API中给我们提供了很多关键字的查询,但是还是不够灵活,因为我们在项目中,会遇见奇葩的业务,我们需要用SpringData中的一个@Query注解。 使用@Query自定义查询 这种查询可以声明在 Repository 方法中,摆脱像命名查询那样的约束,将查询直接在相应的接口方法中声明,结 阅读全文

posted @ 2017-03-11 17:37 airycode 阅读(3920) 评论(0) 推荐(0) 编辑

SpringData关键字查询练习

摘要: 我们在上一节知道SpringData关键字有很多,我就拿几个例子练练手 1.需求我们查询lastName like sun and id < ?的查询 2.需求我们查询WHERE lastName LIKE %? AND id < ? 好了,对着我们上一节那个关键字的表,你可以写出符合你的查询的逻辑 阅读全文

posted @ 2017-03-11 17:04 airycode 阅读(444) 评论(0) 推荐(0) 编辑

SpringData_Repository接口概述

摘要: Repository 接口是 Spring Data 的一个核心接口,它不提供任何方法,开发者需要在自己定义的接口中声明需要的方法 public interface Repository<T, ID extends Serializable> { } Spring Data可以让我们只定义接口,只要 阅读全文

posted @ 2017-03-11 16:37 airycode 阅读(4701) 评论(0) 推荐(2) 编辑

SpringData环境搭建代码编写

摘要: 首先我们在前面的两节已经了解了SpringData是干什么用的?那我们从这节开始我们就开始编码测试SpringData. 1:首先我们从配置文件开始,我们首先需要写一个连接数据库的文件db.properties: 2:因为SpringData 是Spring的一个子项目,我们需要配置Spring的配 阅读全文

posted @ 2017-03-11 16:12 airycode 阅读(205) 评论(0) 推荐(0) 编辑

JPA Spring Data 概述

摘要: JPA Spring Data : 致力于减少数据访问层 (DAO) 的开发量. 开发者唯一要做的,就只是声明持久层的接口,其他都交给 Spring Data JPA 来帮你完成! 框架怎么可能代替开发者实现业务逻辑呢?比如:当有一个 UserDao.findUserById() 这样一个方法声明, 阅读全文

posted @ 2017-03-11 15:47 airycode 阅读(209) 评论(0) 推荐(0) 编辑

SpringData概述

摘要: Spring Data : Spring 的一个子项目。用于简化数据库访问,支持NoSQL 和 关系数据存储。其主要目标是使数据库的访问变得方便快捷。 SpringData 项目所支持 NoSQL 存储: MongoDB (文档数据库) Neo4j(图形数据库) Redis(键/值存储) Hbase 阅读全文

posted @ 2017-03-11 15:41 airycode 阅读(544) 评论(0) 推荐(0) 编辑

导航