SpringBoot连接PostgreSql数据库

版权声明:欢迎转载,转载请注明出处哦! https://blog.csdn.net/qq_41647999/article/details/83311721

目录

一、介绍

1、情况说明

2、安装软件及依赖包

 二、配置

连接数据库

其他情况


一、介绍

1、情况说明

在这里我使用SpringBoot配置Mybaits连接到PostgreSql数据库的。我的源码也会提供给大家(此文末尾),效果如下

数据库:

运行效果:

2、安装软件及依赖包

完整搭建SpringBoot及依赖包:https://blog.csdn.net/qq_41647999/article/details/83214100

需要的SpringBoot代码从Spring官网下载:https://start.spring.io/

Mybaits官网:http://www.mybatis.org/mybatis-3/

最关键的地方是在依赖包那里,需要引用Mybaits和PostgreSql的包。

什么是Mybaits?

说白了和传统的JDBC一样,就是个连接数据库的东西。

更多关于Mybaits,给您推荐一篇文章:https://blog.csdn.net/a909301740/article/details/78698682

将下载的项目解压出来。

 二、配置

如果您的环境配置和我搭建SpringBoot的博文一样的话,用eclipse打开项目。

连接数据库

//数据库的地址以及端口号
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
//账号(默认为postgres)
spring.datasource.username=postgres
//密码
spring.datasource.password=123456ok
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.hbm2ddl.auto=update

其他情况

当然如果您的项目是按照上面的链接搭建的,也可以通过在pom.xml中添加代码,如图。

这里需要注意的一点是,要清楚您使用的Mybaits的依赖包是否符合!

        <dependency>
	    <groupId>org.mybatis.spring.boot</groupId>
	    <artifactId>mybatis-spring-boot-starter</artifactId>
	    <version>1.3.2</version>
	</dependency>
		
	<dependency>
	    <groupId>org.postgresql</groupId>
	    <artifactId>postgresql</artifactId>
	    <scope>runtime</scope>
	</dependency>

积分下载地址:https://download.csdn.net/download/qq_41647999/10739833

如果没有积分,百度云链接:https://pan.baidu.com/s/15UBAeg68mTIaQOy9ES7_Mw提取码:1uuo

SpringBoot连接PostgreSql数据库实现增删改查,点击这里。

猜你喜欢

转载自blog.csdn.net/qq_41647999/article/details/83311721