码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis 一对一、一对多、多对一、多对多

时间:2017-08-13 16:21:38      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:地址   innodb   log   北京市   boot   map   数据   weight   maven依赖   

本项目是  框架架构是 springboot+mybatis

添加maven依赖

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-spring-boot.version}</version>
</dependency>



在 application.properties 配置
#为实体对象所在的包,跟数据库表一一对应
mybatis.typeAliasesPackage=com.exer.demo.entity
#mapper文件的位置
mybatis.mapperLocations=classpath:mapper/*.xml

技术分享


数据库
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
  `id` bigint(30) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `age` int(30) DEFAULT NULL,
  `teacher_id` bigint(30) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO `student` VALUES (‘1‘, ‘weww‘, ‘10‘, ‘1‘);
INSERT INTO `student` VALUES (‘2‘, ‘asdd‘, ‘12‘, ‘1‘);

-- ----------------------------
-- Table structure for teacher
-- ----------------------------
DROP TABLE IF EXISTS `teacher`;
CREATE TABLE `teacher` (
  `id` bigint(30) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `age` int(30) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of teacher
-- ----------------------------
INSERT INTO `teacher` VALUES (‘1‘, ‘tytt‘, ‘32‘);
INSERT INTO `teacher` VALUES (‘2‘, ‘ytyty‘, ‘24‘);

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `id` int(11) NOT NULL COMMENT ‘主键‘,
  `name` varchar(64) NOT NULL COMMENT ‘姓名‘,
  `birthday` date DEFAULT NULL COMMENT ‘生日‘,
  `address` varchar(256) DEFAULT NULL COMMENT ‘地址‘,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES (‘1‘, ‘小明‘, ‘2017-08-12‘, ‘北京市丰台区科怡路‘);
INSERT INTO `user` VALUES (‘2‘, ‘小刚‘, ‘2017-08-12‘, ‘北京市海淀区‘);

-- ----------------------------
-- Table structure for user_device
-- ----------------------------
DROP TABLE IF EXISTS `user_device`;
CREATE TABLE `user_device` (
  `id` int(11) NOT NULL COMMENT ‘主键‘,
  `user_device_name` varchar(64) NOT NULL COMMENT ‘设备名称‘,
  `user_id` int(11) DEFAULT NULL COMMENT ‘用户ID‘,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user_device
-- ----------------------------
INSERT INTO `user_device` VALUES (‘1‘, ‘安卓‘, ‘1‘);
INSERT INTO `user_device` VALUES (‘2‘, ‘IOS‘, ‘1‘);





 

mybatis 一对一、一对多、多对一、多对多

标签:地址   innodb   log   北京市   boot   map   数据   weight   maven依赖   

原文地址:http://www.cnblogs.com/liduanwen/p/7353611.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!