master
潘啟华 6 years ago
parent 69dab0ec97
commit 3b192347fb
  1. 14
      hibernate/src/main/java/config/DBType.java
  2. 3
      hibernate/src/main/java/config/HibernateConfig.java
  3. 12
      mybatis/src/main/java/config/DBType.java
  4. 5
      mybatis/src/main/java/config/MyBatisConfig.java

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

@ -62,7 +62,10 @@ public class HibernateConfig extends InitConfig {
dataSource.setPassword(password);
String url = "";
switch (type) {
case mysql5:
case mysql55:
case mysql57:
case mysql8:
url = type.getUrl(dbHost, dbPort, dbName);
dataSource.setUrl(url);
dataSource.setDriverClassName(type.getDriver().getName());

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

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import model.DataSourceModel;
import org.apache.commons.io.FileUtils;
import org.apache.ibatis.logging.log4j2.Log4j2Impl;
import org.apache.ibatis.session.Configuration;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
@ -40,7 +41,10 @@ public class MyBatisConfig extends InitConfig {
dataSource.setPassword(password);
String url = "";
switch (type) {
case mysql5:
case mysql55:
case mysql57:
case mysql8:
url = type.getUrl(dbHost, dbPort, dbName);
dataSource.setUrl(url);
dataSource.setDriverClassName(type.getDriver().getName());
@ -76,6 +80,7 @@ public class MyBatisConfig extends InitConfig {
beanFactory.registerSingleton(dataSourceModel.getTransactionManagerBean(), transactionManager);
Configuration configuration = new Configuration();
configuration.setLogImpl(Log4j2Impl.class);
PathMatchingResourcePatternResolver resolver=new PathMatchingResourcePatternResolver();
try {
LOG.info("Mapper匹配规则"+dataSourceModel.getMapperXmlPath());

Loading…
Cancel
Save