Mapper动态代理主要有两方面的要素:
1、配置Maopper.xml文件(sql文件)
2、Mapper.java(接口),其中接口的命名方式就是Mapper.xml中的id命名(也叫statement)
主要事项:
1、在Mapper.xml文件中的namepace中的路径是创建Mapper接口代理的路径
2、获取动态代理对象的方法,是通过SqlSession类的getMapper方法,并将要加载的Mapper代理接口类传递进去就可以获得Mapper代理对象。通过动态代理对象就能够进行相应的操作。
InputStream inputSream=Resource.getResourceAsStream(SqlConfigure.xml);
SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream)
SqlSession sqlSession=sqlSessionFactory.openSession();
CustomerMapper cm=SqlSession.getMapper(Customer.class);
本文介绍了MyBatis中实现动态代理的两个关键要素:Mapper.xml文件配置与对应的Mapper接口定义。Mapper.xml文件中包含SQL语句,而Mapper接口则用于定义数据访问层的行为。通过SqlSession的getMapper方法可以获取到Mapper接口的动态代理实例。
1284

被折叠的 条评论
为什么被折叠?



