Giter Site home page Giter Site logo

liuzantian / spring-data-jpa-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from keveon/spring-data-jpa-demo

0.0 3.0 0.0 2.6 MB

本项目是一个SpringDataJpa的demo项目, 旨在演示大部分常用的使用方法。

Shell 6.78% Batchfile 4.81% Java 88.40%

spring-data-jpa-demo's Introduction

Spring Data Jpa 常用功能演示

项目简介

框架介绍

Spring Data JPASpring Data 系列的一部分, 使得轻松实现基于JPA的存储库变得更容易. 该模块处理对基于JPA的数据访问层的增强支持. 它使得更容易构建使用数据访问技术的Spring-powered应用程序.

Spring Data JPA 的目标是通过让一些必须的工作变得更简单, 来显著提高数据访问层的实现. 作为一个开发者, 你写你的仓库界面, 包括自定义查询方法, 而 Spring 给你提供自动实现.

特点

  • 对建立基于Spring 和 JPA 的库的支持
  • 支持 Querydsl predicates和安全类型的 JPA 查询
  • Transparent auditing of domain class
  • 分页支持, 动态查询执行, 可以集成自定义数据访问代码
  • @Query 注明查询引导时验证
  • 支持基于XML的实体映射
  • 引入 @EnableJpaRepositories , 实现基于JavaConfig based仓库配置.

正式开始

准备工作

在开始提到, 本项目采用SpringBoot做基础架构支撑, 项目中使用spring-data-jpa的推荐方法是使用依赖关系管理系统,也就是我们平时所说的包管理器、构建工具.下面两种工具对应的代码段可以复制并粘贴到您的项目中. 如需帮助, 请参阅我们使用 MavenGradle 构建的入门指南.

Maven
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
    </dependencies>
Gradle
    dependencies {
        compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    }

Jpa提供的接口

为了使用方便, spring-data-jpa已经提供了多个接口, 只需要继承其中一个, spring-data-jpa将会自动实现并提供相应的实现. 继承/实现关系如下:

 QueryDslJpaRepository
 ┣━ QueryDslPredicateExecutor
 ┗━ SimpleJpaRepository
     ┣━ JpaSpecificationExecutor
     ┗━ JpaRepository
         ┣━ QueryByExampleExecutor
         ┗━ PagingAndSortingRepository
             ┗━ CrudRepository
                 ┗━Repository
  • Repository: 最基本的接口, 不提供任何功能, 仅作为SpringData的一个标记, 任何直接或间接继承此接口的类或接口, 均会被Spring扫描到, 并提供实现.

  • CrudRepository:提供最基本的CRUD方法.

    • C:Create, 即 insert 语句.
    • R:Read, 即 select 语句.
    • U:Update, 即 update 语句.
    • D:Delete, 即 delete 语句.
  • PagingAndSortingRepository:提供基本的分页及排序功能, 并同时提供CrudRepository接口的功能.

  • QueryByExampleExecutor:

  • JpaRepository:提供同时包含PagingAndSortingRepository、CrudRepository、JpaSpecificationExecutor的功能.

  • JpaSpecificationExecutor:

  • SimpleJpaRepository:

  • QueryDslPredicateExecutor:

  • QueryDslJpaRepository:

附录A:Github 常用按钮说明

  • Watch:关注该项目, 作者有更新的时候, 会在你的 Github 主页有通知消息.
  • Star:收藏该项目, 在你的头像上有一个 "Your stars" 链接, 可以看到你的收藏列表, 以方便下次进来.
  • Fork:复制一份项目到自己的 Github 空间上, 你可以自己开发自己的这个地址项目, 然后 Pull Request 给项目原主人.

联系方式

结束语

  • 真心感谢这些志同道合的人, 这个真的很重要, 也希望你能一起参与(鞠躬)!
  • 同时感谢那些通过私聊方式指出一些错误地方的朋友, 使得该教程能得以更加完善, 真心感谢(鞠躬)!

spring-data-jpa-demo's People

Contributors

keveon avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.