zoukankan      html  css  js  c++  java
  • Spring Data 之 Repository 接口

    1. 介绍

    • Repository是一个空接口,即是一个标记性接口;
    • 若我们定义的接口继承了Repository,则该接口会被IOC容器识别为一个 Repository Bean;
    • 也可以通过@RepositoryDefinition注解,来替代继承Repository接口;
    // 源码:
    public interface Repository<T, ID extends Seriallizable>{
    
    }
    
    // 使用继承的方式
    public interface PersonRepository extends Repository<Person, Integer>{
        Person getByLastName(String lastName);
    }
    
    // 使用注解替代继承
    @RepositoryDefinition(domainClass=Person.class, idClass=Integer.class)
    public interface PersonRepository{
        Person getByLastName(String lastName);
    }
    

    2. Repository接口的子接口

    • CrudRepository:继承Repository,实现了一组CRUD相关的方法;
    • PagingAndSortingRepository:继承CrudRepository,实现了一组分页排序相关的方法;
    • JpaRepository:继承PagingAndSotringRepository,实现一组JPA规范相关的方法;
    • 自定义的XxxRepository:可以继承JpaRepository;
    • JpaSpecificationExecutor:不属于Repository体系,实现一组 JPA Criteria 查询相关的方法;

    参考资料:

  • 相关阅读:
    csuoj 漫漫上学路
    sql函数
    sql基本
    查看webdriver API
    Jmeter应用-接口测试
    http协议
    Jmeter .jmx 改为.jtl
    Jmeter遇到打不开的问题
    测试要点
    apt-get安装mysql
  • 原文地址:https://www.cnblogs.com/linkworld/p/9164331.html
Copyright © 2011-2022 走看看