首先去 下载 mybatis 官网:官网地址
项目图
项目图mybatis的xml配置文件
mybatis-config.xml
studentMppper。xml
studentMapper。xml测试
publicclassBanJiTest {
publicSqlSessionFactory getSessionFactory()throwsIOException{
Stringresource="mybatis-config.xml";
InputStreaminputStream= (InputStream) Resources.getResourceAsStream(resource);
returnnewSqlSessionFactoryBuilder().build(inputStream);
}
@Test
publicvoidtestQuery2()throwsIOException{
System.out.println("显示数据");
SqlSessionFactorysqlSessionFactory= getSessionFactory();
SqlSessionsession=sqlSessionFactory.openSession();
try{
StudentMapperstuMapper= (StudentMapper)session.getMapper(StudentMapper.class);
Studentstu=stuMapper.getStuByBanJiID(1);
System.out.println(stu.toString());
System.out.println(stu.getBanji());
}finally{
session.close();
}
}
}
网友评论