完善myBatis-Generator-extend插件

This commit is contained in:
lsy
2017-11-29 22:09:27 +08:00
parent 7e623ef318
commit 765773a245
7 changed files with 112 additions and 2 deletions
@@ -10,7 +10,7 @@
<parent>
<groupId>com.micro.fast</groupId>
<artifactId>boot-starter</artifactId>
<artifactId>boot-starter-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
@@ -20,10 +20,24 @@
<artifactId>boot-starter-util</artifactId>
<version>${micro.fast.version}</version>
</dependency>
<!--freemarker模板引擎的依赖-->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
<!--数据库连接-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
<build>
@@ -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();
}
}
}
@@ -0,0 +1,4 @@
package com.micro.fast.mybatis.generator.extend.pojo;
public class DatabaseConfig {
}
@@ -0,0 +1,4 @@
package com.micro.fast.mybatis.generator.extend.pojo;
public class MybatisGeneratorConfig {
}
@@ -42,6 +42,7 @@ public class FreemarkerUtil {
cfg.setDirectoryForTemplateLoading(new File(absoluteClasspath+templatesDirUrl));
} catch (IOException e) {
e.printStackTrace();
System.out.println("-----------加载mybatis-generator-extend模板文件失败------------");
}
}
@@ -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;
}
}
@@ -1,7 +1,9 @@
#mybatisGeneratorExtend所需要的参数
db.driverLocation=
db.driverClassName=
db.url=
db.username=
db.password=
mybatisGenerator.pojoPackage=
mybatisGenerator.daoPackage=
mybatisGenerator.daoPackage=
mybatisGenerator.tablesPrefix=