package com.sf.mapperTest;


import com.sf.entity.SysUserInfo;
import com.sf.mapper.SysUserInfoMapper;
import com.sf.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title SysUserInfoMapperTest
 * @description
 * @create 2025/11/16
 */
public class SysUserInfoMapperTest {

    @Test
    public void findByNameTest1(){
        SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSession();
        SysUserInfoMapper sysUserInfoMapper = sqlSession.getMapper(SysUserInfoMapper.class);
        //手动添加%通配符，在实际使用的时候添加
        //如果在测试的时候忘了添加通配符，那就变成了普通的查询语句，匹配全部字符
        List<SysUserInfo> userInfos = sysUserInfoMapper.findByName1("%十%");
        for (SysUserInfo sysUserInfo : userInfos) {
            System.out.println(sysUserInfo);
        }
    }
    @Test
    public void findByNameTest2(){
        SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSession();
        SysUserInfoMapper sysUserInfoMapper = sqlSession.getMapper(SysUserInfoMapper.class);
        List<SysUserInfo> userInfos = sysUserInfoMapper.findByName2("十");
        for (SysUserInfo sysUserInfo : userInfos) {
            System.out.println(sysUserInfo);
        }
    }
    @Test
    public void findByNameTest3(){
        SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSession();
        SysUserInfoMapper sysUserInfoMapper = sqlSession.getMapper(SysUserInfoMapper.class);
        List<SysUserInfo> userInfos = sysUserInfoMapper.findByName3("十");
        for (SysUserInfo sysUserInfo : userInfos) {
            System.out.println(sysUserInfo);
        }
    }
    @Test
    public void findByNameTest5(){
        SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSession();
        SysUserInfoMapper sysUserInfoMapper = sqlSession.getMapper(SysUserInfoMapper.class);
        List<SysUserInfo> userInfos = sysUserInfoMapper.findByName5("十");
        for (SysUserInfo sysUserInfo : userInfos) {
            System.out.println(sysUserInfo);
        }
    }
    @Test
    public void findByIdsTest(){
        SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSession();
        SysUserInfoMapper sysUserInfoMapper = sqlSession.getMapper(SysUserInfoMapper.class);
        List<Integer> ids = new ArrayList<>();
        ids.add(1);
        ids.add(2);
        ids.add(3);
        ids.add(4);
        List<SysUserInfo> userInfoList = sysUserInfoMapper.findByIds(ids);
        for (SysUserInfo sysUserInfo : userInfoList) {
            System.out.println(sysUserInfo);
        }
    }

    @Test
    public void findByIds2Test(){
        SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSession();
        SysUserInfoMapper sysUserInfoMapper = sqlSession.getMapper(SysUserInfoMapper.class);
        List<SysUserInfo> userInfoList = sysUserInfoMapper.findByIds2(3, 7);
        for (SysUserInfo sysUserInfo : userInfoList) {
            System.out.println(sysUserInfo);
        }

    }
}
