赞
踩
在开发过程中单表查询不能满足项目需求分析功能,对于复杂业务来讲,关联的表有几张,甚至几十张并且表与表之间的关系相当复杂。为了能够实业复杂功能业务,就必须进行多表查询,在mybatis中提供了多表查询的结果时映射标签,可以实现表之间的一对一、一对多、多对多关系映射
案例所需数据库脚本
SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for car -- ---------------------------- DROP TABLE IF EXISTS `car`; CREATE TABLE `car` ( `cid` int(11) NOT NULL AUTO_INCREMENT, `cname` varchar(20) DEFAULT NULL, `pid` int(11) NOT NULL, PRIMARY KEY (`cid`) USING BTREE, KEY `cp` (`pid`) USING BTREE, CONSTRAINT `car_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `person` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; -- ---------------------------- -- Records of car -- ---------------------------- INSERT INTO `car` VALUES ('1', '忆柳的购物车', '2'); INSERT INTO `car` VALUES ('2', '梦琪的购物车', '1'); INSERT INTO `car` VALUES ('3', '新柔的购物车', '5'); INSERT INTO `car` VALUES ('4', '慕青的购物车', '3'); INSERT INTO `car` VALUES ('5', '初夏的购物车', '4'); -- ---------------------------- -- Table structure for order -- ---------------------------- DROP TABLE IF EXISTS `order`; CREATE TABLE `order` ( `oid` int(11) NOT NULL AUTO_INCREMENT, `oname` varchar(255) DEFAULT NULL, `pid` int(11) DEFAULT NULL, PRIMARY KEY (`oid`) USING BTREE, KEY `op` (`pid`) USING BTREE, CONSTRAINT `order_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `person` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; -- ---------------------------- -- Records of order -- ---------------------------- INSERT INTO `order` VALUES ('1', '荣耀MagicBook 2019 14英寸轻薄窄边框', '2'); INSERT INTO `order` VALUES ('2', '小米 (MI)Ruby 2019款 15.6英寸金属轻薄', '1'); INSERT INTO `order` VALUES ('3', '戴尔灵越14 燃 14英寸英特尔酷睿i5轻薄窄边框', '3'); INSERT INTO `order` VALUES ('4', '联想(Lenovo)小新14英寸 锐龙版R5', '4'); INSERT INTO `order` VALUES ('5', '红辣椒7X 4+64GB 学生智能手机', '5'); INSERT INTO `order` VALUES ('6', '荣耀10青春版 幻彩渐变', '1'); INSERT INTO `order` VALUES ('7', 'OPPO K1 全面屏手机', '2'); INSERT INTO `order` VALUES ('8', '卡梵蒂GAVADI 鳄鱼皮钱包', '5'); INSERT INTO `order` VALUES ('9', '七匹狼钱包', '2'); INSERT INTO `order` VALUES ('10', '金利来(Goldlion)男士钱包', '1'); -- ---------------------------- -- Table structure for person -- ---------------------------- DROP TABLE
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。