W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
Spring Data Repositories是可以減少樣板代碼的抽象。
例如:
public interface TraderRepository extends DatastoreRepository<Trader, String> { }
Spring Data生成指定接口的有效實(shí)現(xiàn),可以將其自動連接到應(yīng)用程序中。
DatastoreRepository
的Trader
類型參數(shù)是指基礎(chǔ)域類型。在這種情況下,第二個(gè)類型參數(shù)String
是指域類型的鍵的類型。
public class MyApplication { @Autowired TraderRepository traderRepository; public void demo() { this.traderRepository.deleteAll(); String traderId = "demo_trader"; Trader t = new Trader(); t.traderId = traderId; this.tradeRepository.save(t); Iterable<Trader> allTraders = this.traderRepository.findAll(); int count = this.traderRepository.count(); } }
Repositories允許您定義自定義查詢方法(在以下各節(jié)中詳細(xì)介紹),以基于過濾和分頁參數(shù)來檢索,計(jì)數(shù)和刪除。過濾參數(shù)可以是您配置的自定義轉(zhuǎn)換器支持的類型。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: