mybatis使用
首先去 下载 mybatis 官网:官网地址
项目图

mybatis的xml配置文件

studentMppper。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();
}
}
}