zoukankan      html  css  js  c++  java
  • SpringData系列二 Repository接口

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

    1. Repository是一个空接口,即标准接口
    2. 若我们定义的接口继承了Repository,则该接口会被IOC容器识别为一个Repositoty Bean纳入到IOC容器中。进而可以在该接口中定义满足一定规范的方法。
    3. 实际上也可以通过注解的方式定义Repository接口
       1 package com.ntjr.springdata;
       2 
       3 import org.springframework.data.repository.RepositoryDefinition;
       4 
       5 /**
       6  * 
       7  * 1、实现Repository接口 2、通过注解的方式@RepositoryDefinition将一个bean定义为Repository接口
       8  */
       9 @RepositoryDefinition(idClass = Integer.class, domainClass = Person.class)
      10 public interface PersonRepsitory {
      11     // 根据lastName获取对应的person
      12     Person getByLastName(String lastName);
      13 }
      PersonRepository.java
    4. 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 这样的接口就具有通用的数据访问控制层的能力。

      

  • 相关阅读:
    磁盘与文件系统管理
    zookeeper安装部署
    linux打包与压缩
    MongoDB聚合查询
    scrapy中选择器用法
    scrapy基本用法
    python操作mongoDB
    超详细windows安装mongo数据库、注册为服务并添加环境变量
    python beautifulsoup基本用法-文档搜索
    python beautifulsoup基本用法-文档结构
  • 原文地址:https://www.cnblogs.com/zhaobingqing/p/6854439.html
Copyright © 2011-2022 走看看