mybatis配置环境流程

时间:2024-06-03 19:32:14

mybatis配置环境流程

为啥要用mybatis:通过Mybatis实现快速访问后端pgsql、mysql等数据库。

1.修改pom.xml,添加mybatis相关依赖

<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>
</dependency>

2.修改application.yml,修改数据库连接信息

这个application.yml我没有,所以我要在resources这个文件夹目录新建一个。建完之后放入这个代码。注意:配置url,username和password三个参数,依据自己pgsql的环境

spring:
  application:
    name: spring-boot-tutorial
  datasource:
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://127.0.0.1:5432/tvseries?stringtype=unspecified&ApplicationName=tutorial
    username: postgres
    password: 123456
  jackson:
    serialization:
      write-dates-as-timestamps: true  #使用数值timestamp表示日期
 
mybatis.configuration.mapUnderscoreToCamelCase: true

这样下来mybatis应该算是配置好了,不过应该测试一下,不过我还没学测试,所以先掠过。