逆向工程生成的mybatis中mapper文件中,*mapper文件只是接口,而不是类文件。但是却可以通过spring的容器获得实例。

 

例如:

//1、获得mapper代理对象,从spring容器获得。
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");

TbItemMapper itemMapper = applicationContext.getBean(TbItemMapper.class);

原因:通过xml配置,获取bean的时候,mybatis通过JDK的动态代理方式,在启动加载配置文件时,根据配置mapper的xml去生成。

<!-- 数据库连接池 -->
<!-- 加载配置文件 -->
<context:property-placeholder location="classpath:properties/*.properties" />
<!-- 数据库连接池 -->
<bean />
</bean>

参考:http://blog.csdn.net/tanqidong1992/article/details/48026491

参考:https://i.cnblogs.com/EditPosts.aspx?postid=7602084

相关文章:

  • 2021-10-27
  • 2021-05-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案