resultType参数配置

1. 返回值类型为基本数据类型

int getTotalNumber();
<select id="getTotalNumber" resultType="int">
    select count(*) from users
</select>
public void testGetTotalNumber() {
    SqlSession session = MyBatisUtils.getSession();
    UserDao userDao = session.getMapper(UserDao.class);
    System.out.println(userDao.getTotalNumber());
    MyBatisUtils.close(session);
}

2. 返回值为引用数据类型

User getUserById(int id);
select id="getUserById" resultType="com.wy.bean.User">
    SELECT * FROM users WHERE id = #{id}
</select>
public void testGetUserById() {
    SqlSession session = MyBatisUtils.getSession();
    UserDao userDao = session.getMapper(UserDao.class);
    //userDao.getUserById(2);
    System.out.println(userDao.getUserById(2));
    MyBatisUtils.close(session);
}