javascript
Spring JPA 中的Repository体系
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
Repository體系
org.springframework.data.repository.Repository<T, ID>
---- Repository體系的頂級(jí)接口,是個(gè)空接口
?
interface?CrudRepository<T, ID extends?Serializable> extends?Repository<T, ID>
----
<S extends?T> S save(S entity);?//保存
?
<S extends?T> Iterable<S> save(Iterable<S> entities); //批量保存
?
T findOne(ID id); //根據(jù)主鍵id查詢記錄
?
boolean?exists(ID id); //判斷主鍵id對(duì)應(yīng)的記錄是否存在
?
Iterable<T> findAll(); //查詢所有的記錄
?
Iterable<T> findAll(Iterable<ID> ids); //根據(jù)主鍵id集合批量查詢記錄
?
long?count(); //查詢所有記錄數(shù)
?
void?delete(ID id); //根據(jù)主鍵id刪除j;
?
void?delete(T entity); //根據(jù)bean對(duì)象刪除記錄
?
void?delete(Iterable<? extends?T> entities);//根據(jù)bean集合批量刪除記錄
?
void?deleteAll();?//清空數(shù)據(jù)表
?
PagingAndSortingRepository<T, ID extends?Serializable> extends?CrudRepository<T, ID>
?
Iterable<T> findAll(Sort sort);?//查詢所有記錄并根據(jù)指定排序方式排序
?
Page<T> findAll(Pageable pageable);?//查詢所有記錄進(jìn)行分頁(yè)
JpaRepository<T, ID>?extends?PagingAndSortingRepository<T, ID>
?
List<T> findAll(); //查詢所有記錄封裝成list集合
?
List<T> findAll(Sort sort); //查詢所有記錄并排序
?
List<T> findAll(Iterable<ID> ids); //根據(jù)主鍵集合查詢記錄
?
<S extends?T> List<S> save(Iterable<S> entities); //批量保存
?
void?flush(); //刷新數(shù)據(jù)庫(kù)
?
<S extends?T> S saveAndFlush(S entity); //保存并刷新
?
void?deleteInBatch(Iterable<T> entities); //批量刪除
?
void?deleteAllInBatch(); //清空數(shù)據(jù)表
?
T getOne(ID id); //根據(jù)id獲取記錄
轉(zhuǎn)載于:https://my.oschina.net/wxdl/blog/700781
總結(jié)
以上是生活随笔為你收集整理的Spring JPA 中的Repository体系的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 前端代码走查模板
- 下一篇: Leetcode题目解答汇总