首页  

Mybatis SqlSource 与 BoundSql     所属分类 mybatis 浏览量 52
SqlSource用于描述通过注解或XML配置的SQL信息
BoundSql getBoundSql(Object parameterObject) 获取对SQL信息进行封装的BoundSql实例

@Select、@Insert、@Delete、@Update、@SelectProvider、@InsertProvider、@DeleteProvider和@UpdateProvider

public interface SqlSource {
  BoundSql getBoundSql(Object parameterObject);
}

SqlSource接口实现 
DynamicSqlSource ProviderSqlSource RawSqlSource StaticSqlSource 

DynamicSqlSource
XML 和 @Select、@Update等注解配置的SQL信息
这些SQL通常包含动态SQL配置或者参数占位符,需要在Mapper调用时才能确定最终的SQL语句

ProviderSqlSource
通过@SelectProvider、@InsertProvider、@DeleteProvider和@UpdateProvider注解配置的SQL信息

RawSqlSource
XML配置的SQL信息,与DynamicSqlSource唯一的区别在于,其只描述不包含参数占位符且在解析XML配置时就能确定的SQL信息


StaticSqlSource
经过ProviderSqlSource、DynamicSqlSource或者RawSqlSource解析后得到的静态SQL信息


BoundSql
对SQL语句及参数信息的封装,是SqlSource解析后的结果。
Executor 接口方法 BoundSql作为入参,
Executor是将BoundSql作为SQL信息来执行SQL语句的

BoundSql只是封装了SQL语句、参数映射、Mapper调用时传入的参数对象和一个反射工具类,
其这几个属性对应的值都是在构造BoundSql实例时通过构造函数传入

public class BoundSql {

  private final String sql;
  private final List< ParameterMapping> parameterMappings;
  private final Object parameterObject;
  private final Map< String, Object> additionalParameters;
  private final MetaObject metaParameters;

  public BoundSql(Configuration configuration, String sql, List< ParameterMapping> parameterMappings, Object parameterObject) {
    this.sql = sql;
    this.parameterMappings = parameterMappings;
    this.parameterObject = parameterObject;
    this.additionalParameters = new HashMap< >();
    this.metaParameters = configuration.newMetaObject(additionalParameters);
  }
}

上一篇     下一篇
Springboot 过滤器 拦截器 全局异常处理

jackson 笔记

mybatis之MappedStatement getBoundSql

小红书视频下载

羽毛球新手学习顺序

mybtais 动态sql注解