master
潘啟华 6 years ago
parent 3b192347fb
commit 259d903b53
  1. 1
      hibernate/pom.xml
  2. 15
      hibernate/src/main/java/config/DBType.java
  3. 13
      mybatis/src/main/java/config/DBType.java

@ -20,6 +20,7 @@
<commons-lang3.version>3.8.1</commons-lang3.version> <commons-lang3.version>3.8.1</commons-lang3.version>
<commons-io.version>2.6</commons-io.version> <commons-io.version>2.6</commons-io.version>
<mysql.version>8.0.15</mysql.version> <mysql.version>8.0.15</mysql.version>
<!-- <mysql.version>5.1.47</mysql.version>-->
<fastjson.version>1.2.56</fastjson.version> <fastjson.version>1.2.56</fastjson.version>
</properties> </properties>

@ -4,10 +4,10 @@ import org.hibernate.dialect.*;
import java.sql.Driver; import java.sql.Driver;
public enum DBType{ public enum DBType {
mysql5(com.mysql.jdbc.Driver.class, MySQL5Dialect.class), mysql5(com.mysql.cj.jdbc.Driver.class, MySQL5Dialect.class),
mysql55(com.mysql.jdbc.Driver.class, MySQL55Dialect.class), mysql55(com.mysql.cj.jdbc.Driver.class, MySQL55Dialect.class),
mysql57(com.mysql.jdbc.Driver.class, MySQL57Dialect.class), mysql57(com.mysql.cj.jdbc.Driver.class, MySQL57Dialect.class),
mysql8(com.mysql.cj.jdbc.Driver.class, MySQL8Dialect.class); mysql8(com.mysql.cj.jdbc.Driver.class, MySQL8Dialect.class);
private Class<? extends Driver> driver; private Class<? extends Driver> driver;
@ -26,14 +26,15 @@ public enum DBType{
return dialect; return dialect;
} }
public String getUrl(String host,int port,String name){ public String getUrl(String host, int port, String name) {
switch (DBType.valueOf(this.name())){ switch (DBType.valueOf(this.name())) {
case mysql5: case mysql5:
case mysql55: case mysql55:
case mysql57: case mysql57:
case mysql8: case mysql8:
return "jdbc:mysql://" + host + ":" + port + "/" + name + "?serverTimezone=GMT%2b8"; return "jdbc:mysql://" + host + ":" + port + "/" + name + "?serverTimezone=GMT%2b8";
default:throw new RuntimeException("NotFound type:"+this.name()); default:
throw new RuntimeException("NotFound type:" + this.name());
} }
} }

@ -4,9 +4,9 @@ package config;
import java.sql.Driver; import java.sql.Driver;
public enum DBType { public enum DBType {
mysql5(com.mysql.jdbc.Driver.class), mysql5(com.mysql.cj.jdbc.Driver.class),
mysql55(com.mysql.jdbc.Driver.class), mysql55(com.mysql.cj.jdbc.Driver.class),
mysql57(com.mysql.jdbc.Driver.class), mysql57(com.mysql.cj.jdbc.Driver.class),
mysql8(com.mysql.cj.jdbc.Driver.class); mysql8(com.mysql.cj.jdbc.Driver.class);
private Class<? extends Driver> driver; private Class<? extends Driver> driver;
@ -19,14 +19,15 @@ public enum DBType {
return driver; return driver;
} }
public String getUrl(String host,int port,String name){ public String getUrl(String host, int port, String name) {
switch (DBType.valueOf(this.name())){ switch (DBType.valueOf(this.name())) {
case mysql5: case mysql5:
case mysql55: case mysql55:
case mysql57: case mysql57:
case mysql8: case mysql8:
return "jdbc:mysql://" + host + ":" + port + "/" + name + "?serverTimezone=GMT%2b8"; return "jdbc:mysql://" + host + ":" + port + "/" + name + "?serverTimezone=GMT%2b8";
default:throw new RuntimeException("NotFound type:"+this.name()); default:
throw new RuntimeException("NotFound type:" + this.name());
} }
} }
} }

Loading…
Cancel
Save