gpt4 book ai didi

SpringData Repository接口用法解析

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 26 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章SpringData Repository接口用法解析由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

本节主要介绍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 这样的接口就具有通用的数据访问控制层的能力.

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

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

最后此篇关于SpringData Repository接口用法解析的文章就讲到这里了,如果你想了解更多关于SpringData Repository接口用法解析的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com