1.先看项目机构图
2.依赖
org.springframework.boot
spring-boot-starter-parent
2.7.0
1.8
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-jdbc
2.7.0
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.2.2
org.mybatis
mybatis
3.5.9
mysql
mysql-connector-java
5.1.44
com.alibaba
druid
1.1.16
org.projectlombok
lombok
2.配置文件application.yml
server:
port: 8080
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test
username: root
password: 123456
mybatis:
mapper-locations: classpath:com.ty.mapper/*.xml
type-aliases-package: com.ty.bean
logging:
level:
com.ty.mapper: debug
3.创建启动类程序入口
package com.ty;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@MapperScan("com.ty.mapper")
@SpringBootApplication
public class Application {
public static void main(String[] args){
SpringApplication.run(Application.class,args);
}
}
4.写三层架构、bean、controller、mapper、service……
5.写映射文件mapper.xml
select * from user where username = #{username} and password = #{password}
6.数据库表的创建



