如何在Gradle项目中连接PostgreSQL

raj*_*var 4 postgresql database-connection gradle spring-boot microservices

我正在尝试在 gradle 项目中连接 PostgreSQL。我有一个要求进行CRUD操作。

Thi*_*mal 9

添加PostgreSQL依赖于build.gradle

runtimeOnly 'org.postgresql:postgresql'
Run Code Online (Sandbox Code Playgroud)

然后,添加属性application.properties

spring.datasource.url= jdbc:postgresql://localhost:5432/sample
spring.datasource.jdbc-url=${spring.datasource.url}
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.platform=postgres
spring.datasource.username=postgres
spring.datasource.password=password
Run Code Online (Sandbox Code Playgroud)

然后,JPA, jdbctemplate,..在您的代码中实现。