MyBatis源码的学习(3)---MapperMethod是什么?

本文探讨了MyBatis中的MapperMethod类,它用于管理XML中的SQL与Java接口方法之间的映射。解释了为何MyBatis不支持相同statementId的重复,并详细介绍了MapperMethod如何根据statementId找到对应的XML SQL。还提到了MappedStatement的初始化过程及其属性,以及在调用过程中的缓存机制。

今天主要讲MapperMethod类。

public class MapperMethod {
  // sql命令对象,也就是解析sql语句用,对应我们的xml中的sql语句
  private final SqlCommand command;
  //方法签名 对应我们定义在接口中方法,比如 :public User selectUser(String id);
  private final MethodSignature method;

  public MapperMethod(Class<?> mapperInterface, Method method, Configuration config) {
    this.command = new SqlCommand(config, mapperInterface, method);
    this.method = new MethodSignature(config, mapperInterface, method);
  }
// 省略无数行   ;;;
}

看我的注释之后,这个类其实很简单,就是做xml中sql和java类中方法的管理的。

这里说个题外话:为什么MyBatis中不支持同一个statementId出现重复,或者说为什么对应的Mapper接口定义中,我们不能按往常那样方法重名?比如:public User selectUser(String id);  public User selectUser(String id,String useName );

最关键的点在于xml的限制,我们很难做到如何区分俩个 sqlId一样的sql。

 public Sq
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值