All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.meteor.common.database.methods.BatchUpdate Maven / Gradle / Ivy

There is a newer version: 1.0.16
Show newest version
package cn.meteor.common.database.methods;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 批量更新方法实现,条件为主键,选择性更新
 * @author ths
 * @since 1.0.0
 */
@Slf4j
public class BatchUpdate extends AbstractMethod {

	@Override
	public MappedStatement injectMappedStatement(Class mapperClass, Class modelClass, TableInfo tableInfo) {
		String sql = "";
		String additional = tableInfo.isWithVersion() ? tableInfo.getVersionFieldInfo().getVersionOli("item", "item.") : "" + tableInfo.getLogicDeleteSql(true, true);
		String setSql = sqlSet(tableInfo.isWithLogicDelete(), false, tableInfo, false, "item", "item.");
		String sqlResult = String.format(sql, tableInfo.getTableName(), setSql, tableInfo.getKeyColumn(), "item." + tableInfo.getKeyProperty(), additional);
		SqlSource sqlSource = languageDriver.createSqlSource(configuration, sqlResult, modelClass);
		// 第三个参数必须和RootMapper的自定义方法名一致
		return this.addUpdateMappedStatement(mapperClass, modelClass, "batchUpdate", sqlSource);
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy