简体   繁体   English

spring-jdbc 与 spring-data-jdbc 以及它们支持什么

[英]spring-jdbc vs spring-data-jdbc and what are they supporting

I'm curious what is the difference between the spring-jdbc (what I missing in the newest spring release) and spring-data-jdbc.我很好奇 spring-jdbc(我在最新的 spring 版本中缺少的)和 spring-data-jdbc 之间有什么区别。
Is there a difference or just a renaming (in the repositories I don't see this)?有区别还是只是重命名(在存储库中我没有看到这个)?

And is there somewhere described what are the supported targets(DB/JDBC specs/JDK) of the versions?是否在某处描述了版本的支持目标(DB/JDBC 规范/JDK)?

eg for the plain JDBC from oracle I can see that information here: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#01_03_1例如,对于来自 oracle 的普通 JDBC,我可以在这里看到该信息: http : //www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#01_03_1
(eg: JDBC Spec 4.1 in ojdbc7.jar on Java7/Java8 on Oracle DB 12.1/12cR1) (例如:Oracle DB 12.1/12cR1 上 Java7/Java8 上的 ojdbc7.jar 中的 JDBC Spec 4.1)

But I miss that for spring-jdbc - where do I find that information?但是我想念 spring-jdbc - 我在哪里可以找到这些信息?

spring-jdbc

The docs for spring-jdbc are basically here: spring-jdbc的文档基本上在这里:

https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html

Though it doesn't specifically point you to the Spring project spring-jdbc .尽管它并没有特别指出 Spring 项目spring-jdbc This project just provides all of the Spring abstractions over the plain JDBC DataSource that you can use with the Spring Framework.该项目仅提供了可与 Spring 框架一起使用的普通 JDBC DataSource上的所有 Spring 抽象。 For example, Spring's DataSource s which nicely hook into Spring's Transaction management capabilities, like the @Transactional annotation.例如, Spring 的DataSource很好地挂钩了 Spring 的事务管理功能,例如@Transactional注释。 Also, the JdbcTemplate is part of this module, which allows you to execute SQL statements and extract objects from ResultSet s without dealing with exception handling or the nasty details of properly closing statements, connections and the like.此外, JdbcTemplate是该模块的一部分,它允许您执行 SQL 语句并从ResultSet提取对象,而无需处理异常处理或正确关闭语句、连接等令人讨厌的细节。

spring-data-jdbc

spring-data-jdbc , on the other hand, provides the Spring Data abstraction over spring-jdbc .另一方面, spring-data-jdbc提供了spring-jdbc之上的 Spring Data 抽象。 That is, you can create a Spring Data CrudRepository and a simple "entity" (not a JPA entity!) and, as Spring Data does, it will create your queries for you without you having to write native CRUD queries over JDBC, as in this example on the spring-data-examples git repo .也就是说,您可以创建一个 Spring Data CrudRepository和一个简单的“实体”(不是 JPA 实体!),并且,正如 Spring Data 所做的那样,它将为您创建查询,而无需您通过 JDBC 编写本机 CRUD 查询, 如这个例子在spring-data-examples git repo 上

Using the referenced example as a demonstration:使用引用的示例作为演示:

interface CategoryRepository extends CrudRepository<Category, Long> {}

The above code is all you could need (using introspection on the Category object name as the source for the table name (based on a NamingStrategy ) and it's properties as columns, again similar to JPA, but not using JPA .上面的代码就是你所需要的(使用对Category对象名称的自省作为表名的来源(基于NamingStrategy ),它的属性作为列,再次类似于 JPA,但不使用 JPA

Rather than writing your own like so:而不是像这样编写自己的:

@Repository
public class CategoryRepository {
   public void create(Category category) {
      jdbcTemplate.execute("insert...");
   }

  // The rest of my other CRUD operations
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM