springboot(二)集成mybatis与mysql
1.新建一个springboot项目
https://blog.csdn.net/qq_42014192/article/details/88742559
2.然后pom.xml引入mybatis依赖包、mysql驱动包
<!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--springboot-mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
3.application.properties添加数据源
spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://cainiaozhengke.top:3306/springboot01?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
spring.datasource.username = root
spring.datasource.password = root
4.创建项目结构
5.been新建实体类
6.创建mapper接口
1)接口内直接写sql
2)创建mapper接口映射文件
7.创建service层接口与实现
8.创建controller层
9.SpringbootMybatisdemoApplication启动类上面添加扫描接口注解
10.启动SpringbootMybatisdemoApplication类,访问http://localhost:8080/getuser