| | |
| | | package com.lf.server.helper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.lf.server.mapper.all.BasicMapper; |
| | | import com.lf.server.mapper.all.GeomBaseMapper; |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取父Mapper |
| | | * |
| | | * @param name Mapper名 |
| | | * @return BaseMapper |
| | | */ |
| | | public static BasicMapper getBasicMapper(String name) { |
| | | if (StringHelper.isEmpty(name)) { |
| | | return null; |
| | | } |
| | | |
| | | Object obj = getBean(name.trim() + "Mapper"); |
| | | if (!(obj instanceof BasicMapper)) { |
| | | return null; |
| | | } |
| | | |
| | | return (BasicMapper) obj; |
| | | } |
| | | |
| | | /** |
| | | * 获取空间父Mapper |
| | | * |
| | | * @param name Mapper名 |
| | | * @return GeomBaseMapper |
| | | */ |
| | | public static GeomBaseMapper getGeoBaseMapper(String name) { |
| | | if (StringHelper.isEmpty(name)) { |
| | | return null; |
| | | } |
| | | |
| | | Object obj = getBean(name.trim() + "Mapper"); |
| | | if (!(obj instanceof GeomBaseMapper)) { |
| | | return null; |
| | | } |
| | | |
| | | return (GeomBaseMapper) obj; |
| | | } |
| | | |
| | | /** |
| | | * 获取类名 |
| | | * |
| | | * @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); |
| | | } |
| | | } |