com.zengtengpeng.generator.utils.AutoCodeUtils Maven / Gradle / Ivy
package com.zengtengpeng.generator.utils;
import com.zengtengpeng.generator.bean.StartCode;
import com.zengtengpeng.generator.create.CreateCode;
import freemarker.template.Template;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AutoCodeUtils {
public static CreateCode createCode;
/**
* 生成增删改查
* @param startCode
*/
public static void startByBaseCode(StartCode startCode) {
try {
Class.forName("com.zengtengpeng.generator.driver.BaseAutoCodeDriver");
start(startCode);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
/**
* 生成增删改查以及页面
* @param startCode
*/
public static void startByWebAdmin(StartCode startCode) {
try {
Class.forName("com.zengtengpeng.generator.driver.WebAdminAutoCodeDriver");
start(startCode);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
/**
* 开始生成代码
*/
private static void start(StartCode startCode) {
Map param = new HashMap();
String parentPath = startCode.getParentPath();
param.put("parentPath", parentPath);
param.put("packParent", startCode.getParentPack());
param.put("jdbcUrl", startCode.getJdbc());
param.put("user", startCode.getUser());
param.put("password", startCode.getPassword());
List