美文网首页
mybatis使用

mybatis使用

作者: 今天天气很好嗯 | 来源:发表于2017-11-12 13:55 被阅读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();

}

}

}

相关文章

网友评论

      本文标题:mybatis使用

      本文链接:https://www.haomeiwen.com/subject/kodemxtx.html