【发布时间】:2018-09-30 17:18:04
【问题描述】:
我正在学习弹簧靴。我可以将spring boot与hibernate(spring jpa)集成在一起吗?使用 MySQL 数据库访问数据?请帮我。我正在使用 Spring Boot 2.x.x。
【问题讨论】:
-
是的,你可以...
-
网上有很多教程。请检查这些。
标签: spring spring-boot
我正在学习弹簧靴。我可以将spring boot与hibernate(spring jpa)集成在一起吗?使用 MySQL 数据库访问数据?请帮我。我正在使用 Spring Boot 2.x.x。
【问题讨论】:
标签: spring spring-boot
是的,您可以将 Spring Boot 与 Hibernate 集成。您只需要在您的 spring boot 项目中添加以下依赖项即可。
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.12.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jpa</artifactId>
</dependency>
Hibernate 提供了 JPA 的实现。基本上hibernate是一个ORM。 举个例子,开始在你的 POM 中使用具有以下依赖关系的内存数据库。
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
【讨论】:
要使用 JPA,请在您的 POM 中添加以下依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
【讨论】:
当然,您可以将 spring boot 与 spring jpa 集成 - hibernate。 将依赖项添加到项目的 pom.xml 中
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
【讨论】: