第一种:name-value
/**
* driver-class-name
*/
public enum JdbcDriverTypeEnum {
/**
* mysql
*/
MYSQL("MYSQL","com.mysql.cj.jdbc.Driver");
private String name;
private String value;
JdbcDriverTypeEnum(String name, String value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public static String getDriverType(String name) {
for (JdbcDriverTypeEnum type : JdbcDriverTypeEnum.values()) {
if (name.equals(type.getName())) {
return type.value;
}
}
return null;
}
}
第二种:value
public enum JdbcDriverTypeEnum {
/**
* mysql
*/
MYSQL("com.mysql.cj.jdbc.Driver"),
ORACLE("oracle.jdbc.driver.OracleDriver");
private String value;
JdbcDriverTypeEnum(String value) {
this.value = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
网友评论