namespace与接口名相同,id与接口中的方法名相同

// 1、获取sqlSessionFactory对象
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
// 2、获取sqlSession对象
SqlSession openSession = sqlSessionFactory.openSession();
try {
// 3、获取接口的实现类对象,mapper接口没有实现类,但是mybatis会为这个接口生成一个代理对象。
//会为接口自动的创建一个代理对象,代理对象去执行增删改查方法
EmployeeMapper mapper = openSession.getMapper(EmployeeMapper.class);
Employee employee = mapper.getEmpById(1);
System.out.println(mapper.getClass());
System.out.println(employee);
} finally {
openSession.close();
}

}

相关文章:

  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2021-09-27
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-07
  • 2021-07-10
  • 2021-12-30
  • 2021-06-24
  • 2022-12-23
  • 2022-01-05
相关资源
相似解决方案