#yyds干货盘点#MyBatis-plus 从入门到入土 !

敢说敢作敢为, 无怨无恨无悔。这篇文章主要讲述#yyds干货盘点#MyBatis-plus 从入门到入土 !相关的知识,希望能为你提供帮助。
mybatis-plus是一款Mybatis增强工具,用于简化开发,提高效率。下文使用缩写mp  来简化表示mybatis-plus  ,本文主要介绍mp搭配SpringBoot的使用。注:本文使用的mp版本是当前最新的3.4.2,早期版本的差异请自行查阅文档
【#yyds干货盘点#MyBatis-plus 从入门到入土 !】官方网站:??baomidou.com/??
快速入门

  1. 创建一个SpringBoot项目
  2. 导入依赖
    < !-- pom.xml -->
    < ?xml version="1.0" encoding="UTF-8"?>
    < project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    < modelVersion> 4.0.0< /modelVersion>
    < parent>
    < groupId> org.springframework.boot< /groupId>
    < artifactId> spring-boot-starter-parent< /artifactId>
    < version> 2.3.4.RELEASE< /version>
    < relativePath/> < !-- lookup parent from repository -->
    < /parent>
    < groupId> com.example< /groupId>
    < artifactId> mybatis-plus< /artifactId>
    < version> 0.0.1-SNAPSHOT< /version>
    < name> mybatis-plus< /name>
    < properties>
    < java.version> 1.8< /java.version>
    < /properties>
    < dependencies>
    < dependency>
    < groupId> org.springframework.boot< /groupId>
    < artifactId> spring-boot-starter< /artifactId>
    < /dependency>
    < dependency>
    < groupId> org.springframework.boot< /groupId>
    < artifactId> spring-boot-starter-test< /artifactId>
    < scope> test< /scope>
    < /dependency>
    < dependency>
    < groupId> org.springframework.boot< /groupId>
    < artifactId> spring-boot-configuration-processor< /artifactId>
    < /dependency>
    < dependency>
    < groupId> com.baomidou< /groupId>
    < artifactId> mybatis-plus-boot-starter< /artifactId>
    < version> 3.4.2< /version>
    < /dependency>
    < dependency>
    < groupId> mysql< /groupId>
    < artifactId> mysql-connector-java< /artifactId>
    < scope> runtime< /scope>
    < /dependency>
    < dependency>
    < groupId> org.projectlombok< /groupId>
    < artifactId> lombok< /artifactId>
    < /dependency>
    < /dependencies>
    < build>
    < plugins>
    < plugin>
    < groupId> org.springframework.boot< /groupId>
    < artifactId> spring-boot-maven-plugin< /artifactId>
    < /plugin>
    < /plugins>
    < /build>
    < /project>

  3. 配置数据库
    # application.yml
    spring:
    datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/yogurt?serverTimezone=Asia/Shanghai
    username: root
    password: root

    mybatis-plus:
    configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #开启SQL语句打印

  4. 创建一个实体类
    package com.example.mp.po;
    import lombok.Data;
    import java.time.LocalDateTime;
    @Data
    public class User
    private Long id;
    private String name;
    private Integer age;
    private String email;
    private Long managerId;
    private LocalDateTime createTime;

  5. 创建一个mapper接口
    package com.example.mp.mappers;
    import com.baomidou.mybatisplus.core.mapper.BaseMapper;
    import com.example.mp.po.User;
    public interface UserMapper extends BaseMapper< User>

  6. 在SpringBoot启动类上配置mapper接口的扫描路径
    package com.example.mp;

      推荐阅读