mybatis学习

1.加jar包,2个jar包(mybatis,jar,mybatis-connet-java.jar)

2.配置xml,properils

3.书写sql语句即**.xml

4.启动测试

@Test
public void getAllUser(){
//1.启动mybatis框架
//SqlSession-->SqlSessionFactory-->SqlSessionFactioryBuilder
SqlSessionFactoryBuilder sb=new SqlSessionFactoryBuilder ();
InputSteam ins=Resources.getResourcesAsStream("mybatis.xml");
SqlSessionFactory ssf = sfb.build.get(ins);
sqlSession session =ssf.openSession();
List<User> list = session.selectList("cn.java.dao.impl.userDaoImpl.getAllUser");
for(User user:list){
System.out.println(user);
}

}

 

session.selectList()多条,
session.selectOne(路径,参数);单条

posted @ 2018-08-18 22:10  A汉克先生  阅读(124)  评论(0编辑  收藏  举报