PlusUtils.java 723 Bytes
package com.huaheng.common.utils.MybatisPlus;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import java.lang.reflect.Field;

public class PlusUtils {
    public static <T> EntityWrapper getWrapper (T entity)  throws IllegalAccessException {
        EntityWrapper<T> entityWrapper = new EntityWrapper<T>();
        Field[] fields = entity.getClass().getDeclaredFields();
        Field.setAccessible(fields, true);
        for (int i = 0; i < fields.length; i++)   {
            String filedName = fields[i].getName();
            Object filedValue = fields[i].get(entity);
            if (filedValue != null)
                entityWrapper.eq(filedName, filedValue);
        }
        return  entityWrapper;
    }
}