com.github.nomou.mybatis.builder.spi.TableNamingStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mybatis-smart Show documentation
Show all versions of mybatis-smart Show documentation
Mybatis-smart - a light mybatis mapper method implementation proxy
package com.github.nomou.mybatis.builder.spi;
import freework.util.StringUtils2;
public interface TableNamingStrategy {
/**
* 默认表名称策略.
*/
TableNamingStrategy DEFAULT = new TableNamingStrategy() {
private static final String DAO = "Dao";
private static final String MAPPER = "Mapper";
private static final String REPOSITORY = "Repository";
@Override
public String getTableName(final Class> mapperInterface, final Class> domainClass) {
String domainName = null;
if (null != domainClass) {
domainName = domainClass.getSimpleName();
} else {
final String mapperName = mapperInterface.getSimpleName();
if (mapperName.endsWith(MAPPER)) {
domainName = mapperName.substring(0, mapperName.length() - MAPPER.length());
} else if (mapperName.endsWith(DAO)) {
domainName = mapperName.substring(0, mapperName.length() - DAO.length());
} else if (mapperName.endsWith(REPOSITORY)) {
domainName = mapperName.substring(0, mapperName.length() - REPOSITORY.length());
}
}
if (null == domainName || domainName.isEmpty()) {
throw new IllegalStateException(mapperInterface.getCanonicalName() + ": Cannot detect database table name");
}
return StringUtils2.camelCaseToUnderscore(domainName, false);
}
};
String getTableName(final Class> mapperInterface, final Class> domainClass);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy