diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/pom.xml b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/pom.xml index ef5be09..61d86b4 100644 --- a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/pom.xml +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/pom.xml @@ -10,7 +10,7 @@ com.micro.fast - boot-starter + boot-starter-maven-plugin 0.0.1-SNAPSHOT @@ -20,10 +20,24 @@ boot-starter-util ${micro.fast.version} + org.freemarker freemarker + + + mysql + mysql-connector-java + + + ch.qos.logback + logback-core + + + org.slf4j + slf4j-api + diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/db/JdbcConnection.java b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/db/JdbcConnection.java new file mode 100644 index 0000000..cfb5fa8 --- /dev/null +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/db/JdbcConnection.java @@ -0,0 +1,18 @@ +package com.micro.fast.mybatis.generator.extend.db; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class JdbcConnection { + private static final Logger log = LoggerFactory.getLogger(JdbcConnection.class); + static { + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException e) { + log.error("错误{} {}",e,"jdbc驱动加载失败"); + e.printStackTrace(); + } + } + +} diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/pojo/DatabaseConfig.java b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/pojo/DatabaseConfig.java new file mode 100644 index 0000000..5d56092 --- /dev/null +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/pojo/DatabaseConfig.java @@ -0,0 +1,4 @@ +package com.micro.fast.mybatis.generator.extend.pojo; + +public class DatabaseConfig { +} diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/pojo/MybatisGeneratorConfig.java b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/pojo/MybatisGeneratorConfig.java new file mode 100644 index 0000000..e1ca710 --- /dev/null +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/pojo/MybatisGeneratorConfig.java @@ -0,0 +1,4 @@ +package com.micro.fast.mybatis.generator.extend.pojo; + +public class MybatisGeneratorConfig { +} diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/util/FreemarkerUtil.java b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/util/FreemarkerUtil.java index 3a061c1..20042da 100644 --- a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/util/FreemarkerUtil.java +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/util/FreemarkerUtil.java @@ -42,6 +42,7 @@ public class FreemarkerUtil { cfg.setDirectoryForTemplateLoading(new File(absoluteClasspath+templatesDirUrl)); } catch (IOException e) { e.printStackTrace(); + System.out.println("-----------加载mybatis-generator-extend模板文件失败------------"); } } diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/util/PropertiesUtil.java b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/util/PropertiesUtil.java new file mode 100644 index 0000000..a7d0921 --- /dev/null +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/java/com/micro/fast/mybatis/generator/extend/util/PropertiesUtil.java @@ -0,0 +1,67 @@ +package com.micro.fast.mybatis.generator.extend.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.util.Properties; + +public class PropertiesUtil { + private static final Logger log = LoggerFactory.getLogger(Properties.class); + private static final String PROPERTIES_PATH = "mybatisStart.properties"; + private static Properties properties = null; + static { + //1.获取当前项目classpath路径 + String classPath = FreemarkerUtil.class.getResource("/").getPath(); + //2.将mybatisStart.properties配置文件加载到输入流中 + File file = new File(classPath + PROPERTIES_PATH); + if (file.exists()){ + InputStream inputStream = null; + try { + inputStream = new FileInputStream(file); + } catch (FileNotFoundException e) { + log.error("错误{} {}",e,"未找到mybatisStart.properties配置文件"); + e.printStackTrace(); + } + //3.将输入流写入到properties对象中 + if (properties==null){ + properties = new Properties(); + } + try { + properties.load(inputStream); + } catch (IOException e) { + log.error("错误{} {}",e,"mybatisStart.properties配置文件失败"); + e.printStackTrace(); + } + } + } + + /** + * 根据key获取property的value + * @param key 关键字 + * @return + */ + public static String getProperty(String key){ + String property = properties.getProperty(key.trim()); + return property.trim(); + } + + /** + * 根据key获取property的value,如果没有value的话就是默认值 + * @param key 关键字 + * @param defaultValue 默认值 + * @return + */ + public static String getProperty(String key,String defaultValue){ + String property = properties.getProperty(key.trim(), defaultValue); + return property.trim(); + } + + public static Properties getProperties() { + return properties; + } + + public static void setProperties(Properties properties) { + PropertiesUtil.properties = properties; + } +} diff --git a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/resources/mybatisStart.xml b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/resources/mybatisStart.properties similarity index 50% rename from boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/resources/mybatisStart.xml rename to boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/resources/mybatisStart.properties index a73cda5..b56baf4 100644 --- a/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/resources/mybatisStart.xml +++ b/boot-starter/boot-starter-maven-plugin/mybatis-generator-extend/src/main/resources/mybatisStart.properties @@ -1,7 +1,9 @@ +#mybatisGeneratorExtend所需要的参数 db.driverLocation= db.driverClassName= db.url= db.username= db.password= mybatisGenerator.pojoPackage= -mybatisGenerator.daoPackage= \ No newline at end of file +mybatisGenerator.daoPackage= +mybatisGenerator.tablesPrefix= \ No newline at end of file