mysql - 如何将 Spring Boot 应用程序与 MySQL 数据库连接?
问题描述
我是spring
框架的新手,我想将MySQL
位于localhost
Spring Boot 应用程序中的数据库连接起来。
解决方案
我列出了最小配置:
在 pom.xml 中
<!-- JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Use MySQL Connector-J -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
在 application.properties
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/db_example
spring.datasource.username=springuser
spring.datasource.password=ThePassword
你可以在任何地方找到这样的例子。喜欢阅读https://spring.io/guides/gs/accessing-data-mysql/
也检查其他问题:
推荐阅读
- python-3.x - 熊猫:如何使 value_counts() 超过阈值
- python - nn.Linear 的多维工作
- json - 如何根据 id 将 spark 数据框列的所有唯一值合并为单行并将列转换为 json 格式
- regex - 在 TerraForm 资源中使用正则表达式
- react-native - 如何更改反应原生 APK 名称
- node.js - 渲染后下载图片表单node.js
- php - 如何使用数据库中的数据填充我的 html 下拉菜单?
- postgresql - uuid 类型的输入语法无效:PosgreSQL 复制命令中的“”或“null”
- torchtext - AttributeError:类型对象“TabularDataset”没有属性“名称”
- oracle - 优化最大函数子查询