mybatis使用

2017-11-12  本文已影响0人  今天天气很好嗯

首先去 下载 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();

}

}

}

上一篇 下一篇

猜你喜欢

热点阅读