逆向工程生成的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