import com.mapper.UserMapper;
import com.pojo.entity.UserEntity;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public class TestUserParam {
    UserMapper userMapper;
    @Before
    public void before() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatisConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = build.openSession();
        userMapper = sqlSession.getMapper(UserMapper.class);
    }
    @Test
    public void testParam() {
        UserEntity name = userMapper.findUserByParam("难", 11);
    }
    @Test
    public void testParamByMap() {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("name","name");
        hashMap.put("age",11);
        UserEntity name = userMapper.findUserByMap(hashMap);
    }
    /**
     * 验证参数使用@Param
     */
    @Test
    public void testAnnoParam() {
        UserEntity userEntity = new UserEntity();
        userEntity.setName("name");
        userEntity.setAge(11);
        UserEntity userByAnnoParam = userMapper.findUserByAnnoParam(userEntity);
    }

    /**
     * 测试查到到map
     *
     */
    @Test
    public void findByMap() {
        Map<String, Object> byMap = userMapper.findByMap(1);
        System.out.println(byMap.get("name"));
    }
    @Test
    public void findAllByMap() {
        Map<String, Object> byMap = userMapper.findAllByMap();
    }
}
