rams instanceof Map){ @SuppressWarnings("unchecked") Map paramsMap = (Map)params; MapUtils.safeAddToMap(paramsMap, "STARTROW", String.valueOf(rowBounds.getOffset())); MapUtils.safeAddToMap(paramsMap, "ENDROW", String.valueOf(rowBounds.getLimit())); } String sql = boundSql.getSql(); StringBuffer sbSql = new StringBuffer();
@Override public Object plugin(Object target) { // 当目标类是StatementHandler类型时,才包装目标类,否者直接返回目标本身,减少目标被代理的次数 if (target instanceof StatementHandler) { return Plugin.wrap(target, this); } else { return target; } }
@Override public void setProperties(Properties properties) { // TODO Auto-generated method stub }
}
2、配置读取类
/** * 版权所有:华信软件 * 项目名称:ACWS框架类 * 创建者: Wangdf * 创建日期: 2014-4-2 * 文件说明: ACWS框架数据库相关工具类 */ package framework.core.util;
import org.apache.commons.lang.StringUtils; import org.apache.ibatis.session.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
/** * ACWS框架数据库相关工具类 * @author Wangdf */ public class DBUtil { private static final String DBTYPE_MYSQL = "MySQL";//支持的类型:MySQL,Oracle private static final String DBTYPE_ORACLE = "Oracle";//支持的类型:MySQL,Oracle
private static Logger logger = LoggerFactory.getLogger(DBUtil.class); private Configuration configuration = null; private String dbType = ""; private String defaultDateFormat = ""; public DBUtil(Configuration configuration){ if(configuration == null){ logger.error("系统启动失败:MyBatis Configuration 对象为空!"); throw new IllegalArgumentException("系统启动失败:MyBatis Configuration 对象为空!"); } this.configuration = configuration; this.dbType = this.configuration.getVariables().getProperty("dbtype"); if(StringUtils.isBlank(dbType)){ logger.error("数据库类型没有配置!"); } else { logger.info("数据库类型为:"+dbType); } this.defaultDateFormat = this.configuration.getVariables().getProperty("defaultDateFormat"); if(StringUtils.isBlank(this.defaultDateFormat)){ this.defaultDateFormat="yyyy-MM-dd"; logger.info("数据库日期默认格式字符串没有指定!系统默认为:yyyy-MM-dd"); } else { logger.info("数据库日期默认格式字符串:"+this.defaultDateFormat); } } /** * 判断是否是Oracle数据库 * @return * @author wangdf */ public boolean isOracle(){ return DBTYPE_ORACLE.equals(this.dbType); } /** * 判断是否是MySQL数据库 * @return * @author wangdf */ public boolean isMySQL(){ return DBTYPE_MYSQL.equals(this.dbType); } /** * 取得数据库类型 * @return * @author wangdf */ public String getDbType(){ return this.dbType; } /** * 取得默认日期格式 * @return * @author wangdf */ public String getDefaultDateFormat(){ return this.defaultDateFormat; }
}
3、在mybatis全局配置文件设置
< xml version="1.0" encoding="UTF-8" >
|