想实现调试请先搭一个Mybatis连MySQL数据库的环境
附个我的GitHub链接(可能经常有改动,慎用):https://github.com/Frank520lang/mybatis_liang.git
Navicat新建teacher和student两张数据表:
CREATE TABLE `teacher`
(
`id` INT(10) NOT NULL,
`name` VARCHAR(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE = INNODB
DEFAULT CHARSET = utf8;
INSERT INTO teacher(`id`, `name`)
VALUES (1, '秦老师');
CREATE TABLE `student`
(
`id` INT(10) NOT NULL,
`name` VARCHAR(30) DEFAULT NULL,
`tid` INT(10) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fktid` (`tid`),
CONSTRAINT `fktid` FOREIGN KEY (`tid`) REFERENCES `teacher` (`id`)
) ENGINE = INNODB
DEFAULT CHARSET = utf8;
INSERT INTO `student` (`id`, `name`, `tid`)
VALUES (1, '小明', 1);
INSERT INTO `student` (`id`, `name`, `tid`)
VALUES (2, '小红', 1);
INSERT INTO `student` (`id`, `name`, `tid`)
VALUES