Mybatis中Mapper动态开发的注意点

xiaoxiao2021-02-28  103

Mapper接口开发方法只需要编写Mapper接口(相当于Dao开发中的Dao接口),由Mybatis框架根据接口定义创建接口的动态代理对象,代理对象的方法体同Dao接口实现类方法。sqlSession会帮我们生成实现类


Mapper.xml和Mapper接口之间需要满足以下要求:

Mapper.xml中的namespace属性值对应Mapper接口的全类名,实现接口和映射文件的绑定

Mapper.xml中的statement的id值对应Mapper接口中的方法名

Mapper.xml中的statement的parameterType值对应Mapper接口中的方法的输入参数类型

Mapper.xml中的statement的resultType值对应Mapper接口中的方法的输出参数类型


分析: Mapper.xml文件需要与Mapper接口中定义的方法匹配,从而让sqlSession通过Mapper.xml文件获取到接口中定义方法的位置namespace,返回值resultType,方法名id和传入参数ParameterType来生成接口实现类

转载请注明原文地址: https://www.6miu.com/read-59465.html

最新回复(0)