【Mybatis】学习笔记02:实现简单的查
Mybatis02:简单的查
如果你没先去学 增删改 ,然后直接看这篇记录,我想会有些困难。因为该文写的很粗劣,只是简单的截图。所以没基础的建议先去看
有条件查找
创建实体类
接口
映射
测试
查找全部
先在实体类User中重写 toString(
@Override
public String toString(){
return "User{"+
"userId='"+userId+"'"+
",userName='"+userName+"'"+
"userCount='"+userCount+"'"+
",userPassword='"+userPassword+"'"+
"userGrade='"+userGrade+"'"+
",userRegDate='"+userRegDate+"'"+
"userBlance='"+userBlance+"'}";
}
@Test
public void UsersGetAll() throws IOException {
InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
SqlSession sqlSession = sqlSessionFactory.openSession(true);
UsersMapper mapper = sqlSession.getMapper(UsersMapper.class);
List<User> list = mapper.selectUser();
System.out.println(list.get(1));
list.forEach(user -> System.out.println(user));
}
版 权 声 明