mybatis连接Mysql数据库

 

mybatis+Mysql依赖

 1 <!-- Mybatis 依赖-->
 2         <dependency>
 3             <groupId>org.mybatis.spring.boot</groupId>
 4             <artifactId>mybatis-spring-boot-starter</artifactId>
 5             <version>1.3.2</version>
 6         </dependency>
 7         <dependency>
 8             <groupId>org.springframework.boot</groupId>
 9             <artifactId>spring-boot-starter-jdbc</artifactId>
10         </dependency>
11         <dependency>
12             <groupId>mysql</groupId>
13             <artifactId>mysql-connector-java</artifactId>
14             <version>5.1.35</version>
15         </dependency>
16 
17         <dependency>
18             <groupId>org.springframework.boot</groupId>
19             <artifactId>spring-boot-configuration-processor</artifactId>
20             <optional>true</optional>
21         </dependency>

配置文件

 1 #加载Mybatis的xml 在:resources下
 2 mybatis.mapper-locations=classpath:/com/example/demo/api/soap/dao/*.xml
 3 
 4 #设置运行的端口
 5 server.port=8080
 6 
 7 #配置连接mySql数据库
 8 spring.datasource.url=jdbc:mysql://localhost:3306/information_schema?serverTimezone=UTC
 9 spring.datasource.username=root
10 spring.datasource.password=123456
11 spring.datasource.driver-class-name=com.mysql.jdbc.Driver

主类

 1 package com.example.demo;
 2 
 3 import org.mybatis.spring.annotation.MapperScan;
 4 import org.springframework.boot.SpringApplication;
 5 import org.springframework.boot.autoconfigure.SpringBootApplication;
 6 import org.springframework.web.bind.annotation.RestController;
 7 
 8 @SpringBootApplication
 9 @MapperScan({"com.example.demo.api.soap.dao"})
10 @RestController
11 public class DemoApplication {
12 
13     public static void main(String[] args) {
14         SpringApplication.run(DemoApplication.class, args);
15 
16     }
17 
18 }
posted @ 2022-08-11 21:15  勤快的懒羊羊  阅读(436)  评论(0编辑  收藏  举报