Mybatis动态代理

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);

猜你喜欢

转载自blog.csdn.net/ocean_java666/article/details/81141902