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 这样的接口就具有通用的数据访问控制层的能力。

      

  • 相关阅读:
    机器人对话小程序
    partial关键字的含义
    TreeView控件常用写法
    电话本管理程序(实现增删改查功能)
    三层架构
    c# RegistryKey 的相关简单操作
    VS2010程序打包操作(超详细的)
    一些中文.net讲座
    对象表单自动数据邦定
    AspNetForums 2.0中的全文检索
  • 原文地址:https://www.cnblogs.com/zhaobingqing/p/6854439.html
Copyright © 2011-2022 走看看