# spring-data-jdbc **Repository Path**: source-code-study/spring-data-jdbc ## Basic Information - **Project Name**: spring-data-jdbc - **Description**: 当前学习版本:2.1.0-M1 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-03 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README image:https://spring.io/badges/spring-data-jdbc/ga.svg["Spring Data JDBC", link="https://spring.io/projects/spring-data-jdbc#learn"] image:https://spring.io/badges/spring-data-jdbc/snapshot.svg["Spring Data JDBC", link="https://spring.io/projects/spring-data-jdbc#learn"] == Spring Data JDBC image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-jdbc%2Fmaster&subject=Build[link=https://jenkins.spring.io/view/SpringData/job/spring-data-jdbc/] https://gitter.im/spring-projects/spring-data[image:https://badges.gitter.im/spring-projects/spring-data.svg[Gitter]] https://projects.spring.io/spring-data[Spring Data] 项目的主要目标是使使用新数据访问技术(例如非关系数据库,map-reduce框架和基于云的数据服务)的使用Spring支持的应用程序更容易构建。 Spring Data JDBC是较大的Spring Data系列的一部分,可轻松实现基于JDBC的存储库。该模块处理对基于JDBC的数据访问层的增强支持。它使构建使用数据访问技术的Spring支持的应用程序变得更加容易。 它旨在在概念上变得简单。为了实现此目的,它不提供JPA的缓存,延迟加载,回写或其他许多功能。这使得Spring Data JDBC成为简单,有限,自以为是的OR​​M。 == Features - 聚合的CRUD方法的实现。 - @Query 注解 - 支持透明审核(创建,最后更改) - 持续事件的事件 - 集成自定义存储库代码的可能性 - 通过介绍基于JavaConfig的存储库配置 EnableJdbcRepository - 与MyBatis集成 == Code of Conduct 该项目受 https://github.com/spring-projects/.github/blob/e3cc2ff230d8f1dca06535aa6b5a4a23815861d4/CODE_OF_CONDUCT.md[Spring Code of Conduct]。通过参与,您将遵守此行为准则。请向 spring-code-of-conduct@pivotal.io.报告不可接受的行为。 == Getting Started 这是使用Java中的Spring数据存储库的应用程序的快速摘要: [source,java] ---- public interface PersonRepository extends CrudRepository { @Query("SELECT * FROM person WHERE lastname = :lastname") List findByLastname(String lastname); @Query("SELECT * FROM person WHERE firstname LIKE :firstname") List findByFirstnameLike(String firstname); } @Service public class MyService { private final PersonRepository repository; public MyService(PersonRepository repository) { this.repository = repository; } public void doWork() { repository.deleteAll(); Person person = new Person(); person.setFirstname("Jens"); person.setLastname("Schauder"); repository.save(person); List lastNameResults = repository.findByLastname("Schauder"); List firstNameResults = repository.findByFirstnameLike("Je%"); } } @Configuration @EnableJdbcRepositories class ApplicationConfig extends AbstractJdbcConfiguration { @Bean public DataSource dataSource() { return …; } @Bean public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource dataSource) { return new NamedParameterJdbcTemplate(dataSource); } } ---- === Maven 配置 添加Maven依赖项: [source,xml] ---- org.springframework.data spring-data-jdbc ${version}.RELEASE ---- 如果您想要即将发布的主要版本的最新快照,请使用我们的Maven快照存储库并声明适当的依赖版本。 [source,xml] ---- org.springframework.data spring-data-jdbc ${version}.BUILD-SNAPSHOT spring-libs-snapshot Spring Snapshot Repository https://repo.spring.io/libs-snapshot ---- == Getting Help Spring Data遇到问题了吗?我们很乐意为您服务! * 如果您不熟悉Spring Data JDBC,请阅读以下两篇文章“ https://spring.io/blog/2018/09/17/introducing-spring-data-jdbc["Spring Data JDBC 简介"] 和 https://spring.io/blog/2018/09/24/spring-data-jdbc-references-and-aggregates["Spring Data JDBC, 引用和聚合"]. * 检查 https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/[参考文档], 和 https://docs.spring.io/spring-data/jdbc/docs/current/api/[Javadocs]. * 了解Spring基础知识– Spring Data建立在Spring Framework之上,请访问 https://spring.io[spring官方] 网站以获取大量参考文档。如果您只是从Spring开始,请尝试其中的 https://spring.io/guides[指南之一]. * 如果要升级,请查看 https://docs.spring.io/spring-data/jdbc/docs/current/changelog.txt[更改日志中] 的“新功能”。. * 提出一个问题-我们监视 https://stackoverflow.com[stackoverflow.com] 中是否有标有的问题 https://stackoverflow.com/tags/spring-data[`spring-data-jdbc`]. 您还可以在 https://gitter.im/spring-projects/spring-data[Gitter]上与社区聊天。 * 通过jira.spring.io/browse/DATAJDBC报告Spring Data JDBC的 https://jira.spring.io/browse/DATAJDBC[jira.spring.io/browse/DATAJDBC]. == 报告问题 Spring Data使用JIRA作为问题跟踪系统来记录错误和功能请求。如果您要提出问题,请遵循以下建议: * 在记录错误之前,请搜索 https://jira.spring.io/browse/DATAJDBC[issue 追踪] 以查看是否有人已经报告了该问题。 * 如果问题尚不存在,请 https://jira.spring.io/browse/DATAJDBC[创建一个新问题]. * 请在问题报告中提供尽可能多的信息,我们想知道您正在使用的Spring Data的版本和JVM版本。 * 如果您需要粘贴代码或包含堆栈跟踪{code}…{code},请在文本前后使用JIRA 转义符。 * 如果可能,请尝试创建一个复制该问题的测试用例或项目。将链接附加到您的代码或包含您的代码的压缩文件中。 == 源码构建 您不需要从源代码构建就可以使用Spring Data(https://repo.spring.io[repo.spring.io]二进制文件), 但是如果您想尝试最新的和最大的代码,则可以使用 https://github.com/takari/maven-wrapper[maven wrapper]轻松构建Spring Data 。您还需要JDK 1.8。 [source,bash] ---- $ ./mvnw clean install ---- 如果要使用常规mvn命令进行构建,则需要 https://maven.apache.org/run-maven/index.html[Maven v3.5.0 或跟高版本]. _如果您希望提交请求请求,也请参阅 link:CONTRIBUTING.adoc[CONTRIBUTING.adoc] 尤其是在您进行第一次重要变更之前,请先签署“ https://cla.pivotal.io/sign/spring[贡献者协议]” 。_ === 运行集成测试 [source,bash] ---- $ ./mvnw clean install ---- 针对单个内存数据库运行集成测试。 要对所有受支持的数据库运行集成测试,请指定Maven Profile `all-dbs`. [source,bash] ---- ./mvnw clean install -Pall-dbs ---- 这要求 `container-license-acceptance.txt` 在类路径上有一个适当的符号,以表明您接受所用数据库的许可证。 如果您不想接受这些许可证,则可以添加Maven配置文件 `ignore-missing-license`。这将忽略需要明确许可接受的测试。 [source,bash] ---- ./mvnw clean install -Pall-dbs,ignore-missing-license ---- 如果要对其他数据库运行集成测试,可以通过激活适当的Spring Profile来进行。可用的是以下Spring Profile: `db2`, `h2`, `hsql` (default), `mariadb`, `mssql`, `mysql`, `oracle`, `postgres` === 构建参考文件 构建文档也会在不运行测试的情况下构建项目。 [source,bash] ---- $ ./mvnw clean install -Pdistribute ---- 可以从中获得生成的文档 `target/site/reference/html/index.html`. == 模块组 该项目中有许多模块,下面是快速概述: * link:spring-data-relational[Spring Data Relational]:通用的基础结构,抽象了关系数据库访问的一般方面。 * link:spring-data-jdbc[Spring Data JDBC]:对基于JDBC的数据源的存储库支持。 == 例子 * https://gitee.com/source-code-study/spring-data-examples [Spring Data Examples] 包含示例项目,这些项目更详细地解释了特定功能。 == License Spring Data JDBC是在 https://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 许可]下发行的开源软件。