ibatis 单表查询 一对多查询
生成数据库的语句如下: 数据库是试用mysql数据库 /* Navicat MySQL Data Transfer Source Server : mysqlTest Source Server Version : 50022 Source Host : localhost:3306 Source Database : ibatis_db Target Server Type : MYSQL Target Server Version : 50022 File Encoding : 65001 Date: 2013-05-02 22:49:28 */ SET FOREIGN_KEY_ CHECKS=0; -- ---------------------------- -- Table structure for `book` -- ---------------------------- DROP TABLE IF EXISTS `book`; CREATE TABLE `book` ( `oid` int(10) NOT NULL, `name` varchar(50) default NULL, PRIMARY KEY (`oid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of book -- ---------------------------- INSERT INTO `book` VALUES ('1', 'java开发宝典'); -- ---------------------------- -- Table structure for `book_user` -- ---------------------------- DROP TABLE IF EXISTS `book_user`; CREATE TABLE `book_user` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(50) default NULL, `book_oid` int(10) default NULL, PRIMARY KEY (`id`), KEY `FK_user_1` (`book_oid`), CONSTRAINT `FK_user_1` FOREIGN KEY (`book_oid`) REFERENCES `book` (`oid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of book_user -- ---------------------------- INSERT INTO `book_user` VALUES ('1', 'tom', '1'); INSERT INTO `book_user` VALUES ('2', 'lily', '1'); CHECKS=0; -- ---------------------------- -- Table structure for `book` -- ---------------------------- DROP TABLE IF EXISTS `book`; CREATE TABLE `book` ( `oid` int(10) NOT NULL, `name` varchar(50) default NULL, PRIMARY KEY (`oid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of book -- ---------------------------- INSERT INTO `book` VALUES ('1', 'java开发宝典'); -- ---------------------------- -- Table structure for `book_user` -- ---------------------------- DROP TABLE IF EXISTS `book_user`; CREATE TABLE `book_user` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(50) default NULL, `book_oid` int(10) default NULL, PRIMARY KEY (`id`), KEY `FK_user_1` (`book_oid`), CONSTRAINT `FK_user_1` FOREIGN KEY (`book_oid`) REFERENCES `book` (`oid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of book_user -- ---------------------------- INSERT INTO `book_user` VALUES ('1', 'tom', '1'); INSERT INTO `book_user` VALUES ('2', 'lily', '1');
用户评论