zoukankan      html  css  js  c++  java
  • mybatis 一对一、一对多、多对一、多对多

    本项目是  框架架构是 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');





  • 相关阅读:
    线程池ThreadPoolExcecutor介绍
    java类初始化顺序
    CountDownLatch,CyclicBarrier,Semaphore的使用
    设计模式UML图
    windows10磁盘分区后,如何恢复分区,回到未分区之前
    神州战神U盘安装windows10系统,启动项制作好后,在bios中识别不到自己的u盘问题
    项目报错:Invalid bound statement (not found):
    在docker安装tomcat的时候,报错:Caused by: java.lang.IllegalArgumentException: The AJP Connector is configured with secretRequired="true
    PowerDesigner逆向生成MYSQL数据库表结构总结
    mysql导出word的表结构操作
  • 原文地址:https://www.cnblogs.com/liduanwen/p/7353611.html
Copyright © 2011-2022 走看看