首页 > 其他分享 >mp入门教程和api的入门使用

mp入门教程和api的入门使用

时间:2022-08-26 14:16:42浏览次数:91  
标签:lqw userDao user 入门教程 api User import com mp

一、MyBatisPlus简介

1. 入门案例

问题导入

MyBatisPlus环境搭建的步骤?

1.1 SpringBoot整合MyBatisPlus入门程序

①:创建新模块,选择Spring初始化,并配置模块相关基础信息
②:选择当前模块需要使用的技术集(仅保留JDBC)

③:手动添加MyBatisPlus起步依赖
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.4.1</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.1.16</version>
</dependency>

注意事项1:由于mp并未被收录到idea的系统内置配置,无法直接选择加入

注意事项2:如果使用Druid数据源,需要导入对应坐标

④:制作实体类与表结构

(类名与表名对应,属性名与字段名对应)

create database if not exists mybatisplus_db character set utf8;
use mybatisplus_db;
CREATE TABLE user (
            id bigint(20) primary key auto_increment,
            name varchar(32) not null,
            password  varchar(32) not null,
            age int(3) not null ,
            tel varchar(32) not null
);
insert into user values(null,'tom','123456',12,'12345678910');
insert into user values(null,'jack','123456',8,'12345678910');
insert into user values(null,'jerry','123456',15,'12345678910');
insert into user values(null,'tom','123456',9,'12345678910');
insert into user values(null,'snake','123456',28,'12345678910');
insert into user values(null,'张益达','123456',22,'12345678910');
insert into user values(null,'张大炮','123456',16,'12345678910');
public class User {
    private Long id;
    private String name;
    private String password;
    private Integer age;
    private String tel;
    //自行添加getter、setter、toString()等方法
}
⑤:设置Jdbc参数(application.yml
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mybatisplus_db?serverTimezone=UTC
    username: root
    password: root
⑥:定义数据接口,继承BaseMapper
package com.itheima.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.User;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface UserDao extends BaseMapper<User> {
}

⑦:测试类中注入dao接口,测试功能
package com.itheima;

import com.itheima.dao.UserDao;
import com.itheima.domain.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class Mybatisplus01QuickstartApplicationTests {

    @Autowired
    private UserDao userDao;

    @Test
    void testGetAll() {
        List<User> userList = userDao.selectList(null);
        System.out.println(userList);
    }
}

2. MyBatisPlus概述

问题导入

通过入门案例制作,MyBatisPlus的优点有哪些?

2.1 MyBatis介绍

相关文章

  • 【转载】JDK8中computeIfAbsent方法
    转载https://blog.csdn.net/sinat_34241861/article/details/107821860麻烦的方法Map<String,List<String>>map=newHashMap<>();List<String>list;//一般这......
  • 快递物流类API推荐
    最近在网上看到了一些很不错的快递物流类的API,今天在这里整理出来分享给大家~阿里云全国快递物流查询-快递查询接口,可查询快递物流信息近1000+家全国快递查询API,单号自......
  • vue3 onMounted is called when there is no active component
    Vue版本:3.0.0出现的问题:在setup()中onMounted()onActivated(),出现警告:[Vuewarn]:onMountediscalledwhenthereisnoactivecomponentinstancetobeassoc......
  • S/4 HANA 中的 Email Template
    电子邮件是非常常见的业务需求。SAP了解这一点,并在S/4HANA(cloud和onpremise)中引入了非常有趣的功能——EmailTemplate。在本文中,我将提供EmailTemplate的概述和演......
  • 最新小红书数据 小红书爬虫 小红书接口 xhs 小红书api
    小红书数据小红书接口小红书api(小红书爬虫xhsxiaohongshu红书)最新小红书APP接口稳定运行,主流接口都已部署,支持并发请求!只抓取公开数据供作学习用途,不做引流上赞上......
  • 使用Client Credentials保护 API
     Overviewhands-on之前,借用概念篇里的一副图来说明接下来我们要做什么:   在这个场景中的角色有三个:一个ASP.NETCOREWebAPI资源(https://localhost:6001)需......
  • Uncaught Error: Cannot find module './components/xxxx.vue'
    导入组件报异常,有可能两个原因:在组件文件中里面的exportdefault{name:"这里有时候忘记加双引号"}就会找不到该组件在vsCode编辑器中,对vue组件进行重命名,如testcom......
  • 基于 .NET 6 的轻量级 Webapi 框架 FastEndpoints
    大家好,我是等天黑。FastEndpoints 是一个基于.NET6开发的开源webapi框架,它可以很好地替代.NETMinimalAPIs和MVC,专门为开发效率而生,带来了全新的开发模式和编......
  • vue admin template登录的问题
    版本:3.8.0,将其改为本地登录问题后台登录接口尚未开发,为了不影响系统其他接口的开发和测试工作,将vueadmintemplate改为本地登录。解决方案:手动配置token,将登录相关的......
  • 使用PostMan请求Asp.Net Web Api接口错误,Swagger请求正常
    一、使用PostMan请求Asp.NetWebApi报错,如下图:二、使用Swagger请求Asp.NetWebApi正常,如下图:三、遇到如上问题,可能是以下两种问题导致1.先检查WebAPI接口的入参类......