SpringBoot整合Mybatis还是比较简单的,本篇文章讲解使用Mapper.xml来写SQL。
(1)build.gradle文件添加依赖
// https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper
compile group: 'com.github.pagehelper', name: 'pagehelper', version: '5.1.2'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
// https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter
compile group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '1.3.2'
(2)数据库表结构
数据库为wzj,数据库表为teacher,创建表语句如下:
create table teacher( tec_id varchar(16) not null primary key, tec_name varchar(16) not null, tec_age tinyint unsigned, tec_desc varchar(128) );数据库有一条数据
(3)工程结构
controller--控制器包
entity--实体类,和数据库表结构映射
mybatis--mybatis配置
resources/mapper-- sql语句
(4&#