SpringData Repository接口用法解析

2025-05-29 0 33

本节主要介绍Repository接口规范,及其子接口

Repository是一个空接口,即标准接口若我们定义的接口继承了Repository,则该接口会被IOC容器识别为一个Repositoty Bean纳入到IOC容器中。进而可以在该接口中定义满足一定规范的方法。实际上也可以通过注解的方式定义Repository接口

?

1

2

3

4

5

6

7

8

9

10

11

12

13
package com.ntjr.springdata;

import org.springframework.data.repository.RepositoryDefinition;

/**

*

* 1、实现Repository接口 2、通过注解的方式@RepositoryDefinition将一个bean定义为Repository接口

*/

@RepositoryDefinition(idClass = Integer.class, domainClass = Person.class)

public interface PersonRepsitory {

// 根据lastName获取对应的person

Person getByLastName(String lastName);

}

PersonRepository.java

Repository的子接口

SpringData Repository接口用法解析

    org.springframework.data.repository.CrudRepository<T, ID> :实现了一组CRUD的方法

    org.springframework.data.repository.PagingAndSortingRepository<T, ID>:实现了一组分页排序相关的方法

    org.springframework.data.jpa.repository.JpaRepository<T, ID>:实现了一组JPA相关规范的方法

    自定义的接口继承JpaRepository 这样的接口就具有通用的数据访问控制层的能力。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。

原文链接:https://www.cnblogs.com/zhaobingqing/p/6854439.html

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 SpringData Repository接口用法解析 https://www.kuaiidc.com/117806.html

相关文章

发表评论
暂无评论