| | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.aop.support.AopUtils; |
| | | |
| | | import java.lang.reflect.Type; |
| | | |
| | | /** |
| | | * 类帮助类 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据BaseMapper创建实体类 |
| | | * |
| | | * @param baseMapper 父Mapper |
| | | * @return 实体类 |
| | | */ |
| | | public static Object createEntityByMapper(BaseMapper baseMapper) { |
| | | String className = baseMapper.getClass().getName().replace(".mapper", ".entity").replace("Mapper", "Entity"); |
| | | |
| | | return createInstance(className); |
| | | } |
| | | |
| | | /** |
| | | * 获取Bean |
| | | * |
| | | * @param className 类名 |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取类名 |
| | | * |
| | | * @param baseMapper 父Mapper |
| | | * @return 类名 |
| | | */ |
| | | public static String getClassName(BaseMapper baseMapper) { |
| | | Type[] genericInterfaces = AopUtils.getTargetClass(baseMapper).getGenericInterfaces(); |
| | | |
| | | return genericInterfaces[0].getTypeName(); |
| | | } |
| | | |
| | | /** |
| | | * 根据Mapper类名获取实体类的Class |
| | | * |
| | | * @param className Mapper类名 |
| | | * @return 实体类的Class |
| | | */ |
| | | public static Class getEntityClass(String className) { |
| | | try { |
| | | className = className.replace(".mapper", ".entity").replace("Mapper", "Entity"); |
| | | Class clazz = Class.forName(className); |
| | | |
| | | return clazz; |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据BaseMapper创建实体类 |
| | | * |
| | | * @param baseMapper 父Mapper |
| | | * @return 实体类 |
| | | */ |
| | | public static Object createEntityByMapper(BaseMapper baseMapper) { |
| | | String className = getClassName(baseMapper); |
| | | className = className.replace(".mapper", ".entity").replace("Mapper", "Entity"); |
| | | |
| | | return createInstance(className); |
| | | } |
| | | } |