tk.mybatis 操作工具类 SimpleMapperUtils

import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;
import java.util.*;

/**
 * 简化的数据库操作类
 */
public class SimpleMapperUtils {

    /**
     *  只用于equal级联操作
     */
    public static  List simpleEqualListMapper(Mapper mapper, Class tClass, Object... objects){
        Example example = new Example(tClass);
        Example.Criteria criteria = example.createCriteria();
        int length = objects.length;
        for(int i = 0 ; i < length ; i++){
            criteria.andEqualTo(objects[i].toString(), objects[++i]);
        }
        return mapper.selectByExample(example);
    }

   /**
     *  只用于in级联操作
     */
    public static  List simpleInListMapper(Mapper mapper, Class tClass, Object... objects){
        Example example = new Example(tClass);
        Example.Criteria criteria = example.createCriteria();
        int length = objects.length;
        for(int i = 0 ; i < length ; i++){
            criteria.andIn(objects[i].toString(), (Iterable)objects[++i]);
        }
        return mapper.selectByExample(example);
    }

/**
 *  只用于Equal级联操作
 */
public static   int simpleEqualCountMapper(Mapper mapper, Class tClass, Object... objects){
        Example example = new Example(tClass);
        Example.Criteria criteria = example.createCriteria();
        int length = objects.length;
        for(int i = 0 ; i < length ; i++){
            criteria.andEqualTo(objects[i].toString(), objects[++i]);
        }
        return  mapper.selectCountByExample(example);
    }
}


你可能感兴趣的:(tk.mybatis 操作工具类 SimpleMapperUtils)