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:设置一下编码,不然中文注释可能会报错

 

 

 

posted @ 2022-05-26 10:30  正怒月神  阅读(2270)  评论(0编辑  收藏  举报