
tech.jhipster.service.mybatis.MybatisUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jhipster-framework Show documentation
Show all versions of jhipster-framework Show documentation
Server-side library used by applications created with the BegCode generator, see https://www.begcode.com/ for more information on BegCode
package tech.jhipster.service.mybatis;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
import com.diboot.core.exception.BusinessException;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Objects;
import static com.diboot.core.util.ContextHelper.getBean;
public class MybatisUtil {
private static DbType dbType;
public static DbType getDatabaseTypeEnum() {
if (Objects.nonNull(dbType)) {
return dbType;
}
try {
DataSource dataSource = getBean(DataSource.class);
dbType = JdbcUtils.getDbType(dataSource.getConnection().getMetaData().getURL());
return dbType;
} catch (SQLException e) {
e.printStackTrace();
throw new BusinessException("获取数据库类型失败");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy