项目代码地址:
https://gitee.com/xuluj/springboot_integrates_mybatis.git
开发环境:
- 开发工具:Intellij IDEA 2018.3.2
- springboot: 2.1.2
- jdk:1.8.0_172
- maven:3.5.4
步骤:
1.使用 IDEA建立springboot项目
File-->New-->Project
2.添加项目依赖
3.创建数据库及表
CREATE DATABASE mytest;
USE mytest;
CREATE TABLE user(
user_id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
user_name VARCHAR(255) NOT NULL ,
password VARCHAR(255) NOT NULL ,
age INTEGER
) ENGINE=INNODB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8;
4.application.yml配置文件
server:
port: 8090
spring:
datasource:
username: root
password: 615610
url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
## 该配置节点为独立的节点,有很多同学容易将这个配置放在spring的节点下,导致配置无法被识别
mybatis:
mapper-locations: classpath:mapping/*Mapper.xml #注意:一定要对应mapper映射xml文件的所在路径
type-aliases-package: com.xlj.springboot_mybatis.*.entity # 注意:对应实体类的路径
5.项目文件结构