Mapper动态代理方式

Mapper接口开发须要遵循如下规范:程序员

一、  Mapper.xml文件中的namespacemapper接口的类路径相同。sql

二、  Mapper接口方法名和Mapper.xml中定义的每一个statementid相同 mybatis

三、  Mapper接口方法的输入参数类型和mapper.xml中定义的每一个sql parameterType的类型相同app

四、  Mapper接口方法的输出参数类型和mapper.xml中定义的每一个sqlresultType的类型相同spa

  • selectOneselectList代理

动态代理对象调用sqlSession.selectOne()sqlSession.selectList()是根据mapper接口方法的返回值决定,若是返回list则调用selectList方法,若是返回单个对象则调用selectOne方法。xml

 

  • namespace对象

mybatis官方推荐使用mapper代理方法开发mapper接口,程序员不用编写mapper接口实现类,使用mapper代理方法时,输入参数能够使用pojo包装对象或map对象,保证dao的通用性。接口

相关文章
相关标签/搜索