package com.qidi.platform.base.service; import java.util.List; import org.apache.ibatis.mapping.ResultMap; import org.apache.ibatis.mapping.ResultMapping; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; public abstract class BaseService { Logger logger = Logger.getLogger(BaseService.class); @Autowired SqlSessionFactory sessionFactory; // myBatis核心工厂 /** * 方法名: propertyToColumn 功能描述: property转Column * * @author yangtao * @since 2016年10月10日 下午5:44:48 * * @param * @return String */ public String propertyToColumn(String resultMapId, String property){ ResultMap resultMap = sessionFactory.getConfiguration().getResultMap(resultMapId); if (null == resultMap) { logger.error("resultMap 对象为空"); return null; } List<ResultMapping> resultMappings = resultMap.getResultMappings(); if (null == resultMappings) { logger.error("resultMappings 对象为空"); return null; } Object[] resultMapping = resultMappings.stream().filter(map -> property.equals(map.getProperty())).map(ResultMapping::getColumn).toArray(); if (resultMapping.length < 1){ return null; }else { return resultMapping[0].toString(); } } }
最近下载更多