package com.bohuikeji.frame.module.admin.mp.method;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.bohuikeji.frame.module.admin.mp.SqlMethod;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 使用ID，查询一条数据的指定列
 * @author 孙劲辉
 */
public class SelectColumnById extends AbstractMethod {
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        SqlMethod sqlMethod = SqlMethod.SELECT_COLUMNS_ID;
        // 进行预编译得到sqlSource对象
        SqlSource sqlSource = languageDriver.createSqlSource(
                configuration, String.format(sqlMethod.getSql(),tableInfo.getTableName(),tableInfo.getKeyColumn()),Object.class);
        //添加到delete操作的Statement中也就是相当于将预编译sql和其它的delete相关的编译后的sql存在一起
       return this.addSelectMappedStatement(mapperClass,sqlMethod.getMethod(),sqlSource,Object.class,tableInfo);
    }
}
