add
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.qiaoba.common.base.enums;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.qiaoba.common.base.exceptions.ServiceException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@ -15,11 +16,13 @@ import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
public enum DataBaseEnum {
|
||||
|
||||
// ip/port/database
|
||||
|
||||
/**
|
||||
* MySQL
|
||||
*/
|
||||
MY_SQL("MySQL",
|
||||
"jdbc:mysql://localhost:3306/{}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true",
|
||||
"jdbc:mysql://{}:{}/{}?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowMultiQueries=true",
|
||||
"com.mysql.cj.jdbc.Driver"),
|
||||
|
||||
/**
|
||||
@ -59,4 +62,21 @@ public enum DataBaseEnum {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDriver(String type) {
|
||||
for (DataBaseEnum dataBaseEnum : values()) {
|
||||
if (dataBaseEnum.getType().equals(type)) {
|
||||
return dataBaseEnum.driver;
|
||||
}
|
||||
}
|
||||
throw new ServiceException(StrUtil.format("未找到数据库驱动, Type: {}", type));
|
||||
}
|
||||
|
||||
public static String getUrl(String type, String ip, String port, String database) {
|
||||
for (DataBaseEnum dataBaseEnum : values()) {
|
||||
if (dataBaseEnum.getType().equals(type)) {
|
||||
return StrUtil.format(dataBaseEnum.url, ip, port, database);
|
||||
}
|
||||
}
|
||||
throw new ServiceException(StrUtil.format("未找到数据库Url, Type: {}", type));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user