springboot 连接 postgresql
Posted 正怒月神
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot 连接 postgresql相关的知识,希望对你有一定的参考价值。
一,JPA 方式
POM
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
application.yml
spring:
application:
name: shipcenter
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://xxxxx:5432/leadtrans
username: xxx
password: xxx
jpa:
generate-ddl: false
hibernate:
ddl-auto: none
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
database: postgresql
show-sql: false
二,Mybatis-plus
POM
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.4</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
application.yml
spring:
application:
name: shipcenter
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://xxxxx:5432/leadtrans
username: xxxx
password: xxxx
mybatis-plus:
configuration:
map-underscore-to-camel-case: false #关闭驼峰转下划线
global-config:
db-config:
update-strategy: ignored #null也会更新
PS:设置一下编码,不然中文注释可能会报错
以上是关于springboot 连接 postgresql的主要内容,如果未能解决你的问题,请参考以下文章
Docker:Springboot 容器无法连接到 PostgreSql 容器连接错误
Docker/Hibernate/PostgreSQL - 将运行 Hibernate/SpringBoot 应用程序的容器与 postgreSQL 容器不工作连接
SpringBoot+PostgreSQL/Oracle/MySQL连接配置