MybatisPlus快速入门,整个SpringBoot快速开发DAO层

第一步:创建一个SpringBoot工程,只选择MySQL驱动即可

MybatisPlus快速入门,整个SpringBoot快速开发DAO层_第1张图片

第二步:导入MybatisPlus依赖


    com.baomidou
    mybatis-plus-boot-starter
    3.4.2

 第三步:在application.yml中配置数据源

spring:
  datasource:
    password: 123456
    username: root
    url: jdbc:mysql://localhost:3306/homework?serverTimezone=Asia/Shanghai
    driver-class-name: com.mysql.cj.jdbc.Driver

第四步:编写实体类

package com.gaoyang.pojo;

public class Student {
    private String sno;
    private String sname;
    private String sex;
    private Integer age;
    private String dept;

    public String getSno() {
        return sno;
    }

    public void setSno(String sno) {
        this.sno = sno;
    }

    public String getName() {
        return sname;
    }

    public void setName(String sname) {
        this.sname = sname;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getDept() {
        return dept;
    }

    public void setDept(String dept) {
        this.dept = dept;
    }

    @Override
    public String toString() {
        return "Student{" +
                "sno='" + sno + '\'' +
                ", sname='" + sname + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", dept='" + dept + '\'' +
                '}';
    }
}

第五步:编写dao接口

@Mapper
public interface StudentMapper extends BaseMapper {
}

第六步:测试获取全部数据selectAll

@SpringBootTest
class Mybatisplus01HelloworldApplicationTests {
    @Autowired
    private StudentMapper studentMapper;

    @Test
    void testMp() {
        List students = studentMapper.selectList(null);
        System.out.println(students);
    }
}

你可能感兴趣的:(数据库相关框架,spring,boot,mybatis,java)