com.gccloud.starter.common.mybatis.injector.methods.SelectBatchByIds Maven / Gradle / Ivy
package com.gccloud.starter.common.mybatis.injector.methods;
/**
* 根据ID集合,批量查询数据
*
* @author liuchengbiao
* @date 2021/7/7 2:02 下午
*/
import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
public class SelectBatchByIds extends AbstractMethod {
@Override
public MappedStatement injectMappedStatement(Class> mapperClass, Class> modelClass, TableInfo tableInfo) {
SqlMethod sqlMethod = SqlMethod.SELECT_BATCH_BY_IDS;
String selectColumn = sqlSelectColumns(tableInfo, false);
if (StringUtils.equals(StringPool.STAR, selectColumn)) {
// 修改select * 为 select 具体列名,保证符合上云规范
selectColumn = tableInfo.getAllSqlSelect();
}
SqlSource sqlSource = languageDriver.createSqlSource(configuration, String.format(sqlMethod.getSql(),
selectColumn, tableInfo.getTableName(), tableInfo.getKeyColumn(),
SqlScriptUtils.convertForeach("#{item}", COLLECTION, null, "item", COMMA),
tableInfo.getLogicDeleteSql(true, true)), Object.class);
return addSelectMappedStatementForTable(mapperClass, getMethod(sqlMethod), sqlSource, tableInfo);
}
}