StudySpringBoot01ApplicationTests.java 2.0 KB
package com.example.studyspringboot01;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.studyspringboot01.dao.UserDao;
import com.example.studyspringboot01.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.ArrayList;
import java.util.List;

@SpringBootTest
class StudySpringBoot01ApplicationTests {

   @Autowired
    private UserDao userDao;

    //查询所有
   @Test
    public void selectAllTest(){
       List<User> userList = userDao.selectList(null);
       userList.forEach(s -> System.out.println(s));
   }

    //新增
    @Test
    public void save(){
       User user = new User();
       user.id = 1;
       user.username = "dingxiongchao";
       user.password = "223344";
       userDao.insert(user);
    }

    //删除
    @Test
    public void delete(){
       userDao.deleteById(123);
    }

    //修改
    @Test
    public void update(){
       User user = new User();
       user.id = 13;
       user.username = "1333";
       user.password = "1343";
       userDao.updateById(user);
    }

    //查询单个
    @Test
    public void selectById(){
       userDao.selectById(122);
    }

    //分页查询
    @Test
    public void page(){
        Page page = new Page(1,2);
        Page page1 = userDao.selectPage(page, null);
        System.out.println("分页查询,当前是多少页:"+ page1.getCurrent());
        System.out.println("分页查询,一页能查询几条数据:"+ page1.getSize());
        System.out.println("分页查询,一共多少页:"+ page1.getPages());
        System.out.println("分页查询,一共多少条数据:"+ page1.getTotal());
        System.out.println("分页查询,当前页显示数据:" + page1.getRecords());
    }

    //多选删除
    @Test
    public void deleteByIds(){
       List<Integer> list = new ArrayList<>();
       list.add(4);
       list.add(5);
       list.add(9);
       userDao.deleteBatchIds(list);
    }






}