package com.example.springbootmpdemo.mapper;

import com.example.springbootmpdemo.domain.Student;
import org.junit.jupiter.api.Test;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class TestStudentMapper {

    @Autowired
    private StudentMapper studentMapper;

    @Test
    public void testStudentMapper() {

        Student student = studentMapper.selectById(1);
        System.out.println(student);

    }

    @Test
    public void testAdd() {

        Student student = new Student(null,"王洋","wy@itbaizhan.com","m",26);

        studentMapper.insert(student);

        //MyBatisPlus插入成功后直接获取主键的值
        System.out.println(student.getId());

    }

    @Test
    public void testUpdate() {

        //创建实体类对象
        Student student = new Student();

        //设置需要更新的属性
        student.setName("吴大");

        //设置需要修改的数据id
        student.setId(1);

        //根据主键进行更新，没有设置的属性不更新
        studentMapper.updateById(student);
    }

    /**
     *      根据ID删除
     */
    @Test
    public void testDeleteById() {

        studentMapper.deleteById(591446018);

    }

}
