13、Spring Data 持久化层搭建与测试实践

Spring Data 持久化层搭建与测试实践

1. Spring Data 仓库定义

Spring Data 提供了一组用于定义仓库的接口,这里主要使用 CrudRepository PagingAndSortingRepository 接口:
- CrudRepository :提供对数据库中数据进行基本的创建、读取、更新和删除操作的标准方法。
- PagingAndSortingRepository :在 CrudRepository 接口的基础上增加了分页和排序的支持。

以下是各个仓库类的定义:

// Product 仓库类
public interface ProductRepository extends
    PagingAndSortingRepository <ProductEntity, String>,
    CrudRepository<ProductEntity, String> {
    Optional<ProductEntity> findByProductId(int productId);
}

// Recommendation 仓库类
public interface RecommendationRepository extends CrudRepository 
<RecommendationEntity, String> {
    List<Rec
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值