All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lodsve.mybatis.configuration.LodsveConfigurationCustomizer Maven / Gradle / Ivy

/*
 * Copyright (C) 2018  Sun.Hao
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */

package lodsve.mybatis.configuration;

import lodsve.core.utils.StringUtils;
import lodsve.mybatis.plugins.pagination.PaginationInterceptor;
import lodsve.mybatis.plugins.repository.BaseRepositoryInterceptor;
import lodsve.mybatis.type.TypeHandlerScanner;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.type.TypeHandler;

import java.util.Arrays;

/**
 * 扩展mybatis的configuration,加入以下内容:.
 * 
    *
  1. 字段名和数据库column名符合驼峰命名规范
  2. *
  3. 加入两个个插件:分页、通用DAO
  4. *
* 这样就可以省略mybatis的所有基本配置 * * @author sunhao([email protected]) */ public class LodsveConfigurationCustomizer implements ConfigurationCustomizer { private boolean mapUnderscoreToCamelCase; private String[] enumsLocations; public LodsveConfigurationCustomizer(boolean mapUnderscoreToCamelCase, String[] enumsLocations) { this.mapUnderscoreToCamelCase = mapUnderscoreToCamelCase; this.enumsLocations = enumsLocations; } @Override public void customize(Configuration configuration) { configuration.setMapUnderscoreToCamelCase(mapUnderscoreToCamelCase); configuration.addInterceptor(new PaginationInterceptor()); configuration.addInterceptor(new BaseRepositoryInterceptor()); if (ArrayUtils.isNotEmpty(enumsLocations)) { TypeHandler[] handlers = new TypeHandlerScanner().find(StringUtils.join(enumsLocations, ",")); Arrays.stream(handlers).forEach(configuration.getTypeHandlerRegistry()::register); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy