zoukankan      html  css  js  c++  java
  • springboot 整合mybatis

    一、前提条件:连接数据库

    二、步骤

    1、导包

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.1.3</version>
    </dependency>

    2、创建pojo实体类

    3、创建mapper 接口

    作用:写CRUD方法

    4、创建mapper.xml文件

    作用:写SQL语句

    5、配置yml

    # 整合 mybatis
    mybatis:
      mapper-locations: classpath:mybatis/*.xml
      type-aliases-package: com.wt.pojo

    注意:mappper 和 locations 踩过坑

    6、开启扫描

    在启动入口添加扫描注解

    @MapperScan("com.wt.mapper")

    三、案例

    1、创建数据库 添加数据

    CREATE TABLE employee(
        id int auto_increment PRIMARY KEY,
        gender int COMMENT "0 女 1男",
        name VARCHAR(20) COMMENT "员工姓名",
        email VARCHAR(50) COMMENT "员工邮箱",
        birth date COMMENT "生日",
        depart_id int COMMENT "对应部门表的id"
    )ENGINE=INNODB DEFAULT charset=utf8
    
    
    create table department(
        id int auto_increment PRIMARY KEY,
        name VARCHAR(20)
    )ENGINE=INNODB default charset=utf8

    2、待续,

  • 相关阅读:
    第七周总结
    结对开发nabcd
    第六周总结
    地铁售票设计思想及部分代码
    第二周总结
    进度总结(地铁查询购票)
    第三周总结
    冲刺四
    冲刺三
    冲刺2
  • 原文地址:https://www.cnblogs.com/wt7018/p/13376160.html
Copyright © 2011-2022 走看看