项目结构:
需要的依赖: jdbc,mybatis,postgresql
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<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>
yml配置文件
spring:
mvc:
view:
prefix:/
suffix:.html
datasource:
platform:postgres
url:jdbc:postgresql://localhost:5432/zjtest
username:postgres
password:
driver-class-name:org.postgresql.Driver
mybatis:
config-location:classpath:mybatis/mybatis-config.xml
mapper-locations:classpath:mybatis/mapper/*.xml
mybatis-config.xml配置文件
userMapper.xml
userMapper接口
实体类
controller调用
控制台