All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mybatis.generator.api.plus.MybatisUtilHtmlBack Maven / Gradle / Ivy

The newest version!
package org.mybatis.generator.api.plus;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;

import java.io.*;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author wangfupeng
 */
public class MybatisUtilHtmlBack {

    public static void writeAllPage(IntrospectedTable introspectedTable, String htmlPath, String modelUrl, String fileServer, String serverUrl, String basePackage, String aspectPackage, String tokenErrorStatus, String encryptPasswordMethod) {
        writeJsCommonJqueryJs(htmlPath, serverUrl);
        writeJsCommonMd5Js(htmlPath, serverUrl);
        writeJsCommonSha256Js(htmlPath, serverUrl);
        writeJsCustomCustomJs(htmlPath, serverUrl, tokenErrorStatus);
        writeCssCustomCustomCss(htmlPath, serverUrl, tokenErrorStatus);
        writeJsCommonServerJs(htmlPath, serverUrl, tokenErrorStatus, fileServer);
        writeJsCommonValueJs(htmlPath, serverUrl, tokenErrorStatus, fileServer);
        writeCssCommonServerCss(htmlPath, serverUrl, tokenErrorStatus, fileServer);
        writeIndexPage(introspectedTable, htmlPath, modelUrl);
        writeCustomIndexJs(introspectedTable, htmlPath, modelUrl);
        writeCustomIndexCss(introspectedTable, htmlPath, modelUrl);
        writeLoginPage(introspectedTable, htmlPath, modelUrl, encryptPasswordMethod);
        writeLeftFramePage(introspectedTable, htmlPath, modelUrl);
        writeBlankPage(htmlPath, modelUrl);
        writeJsPlusTrumbowygJs(htmlPath, serverUrl);
        writeJsPlusJjlcJs(htmlPath, serverUrl);
        writeJsPlusTrumbowygCss(htmlPath, serverUrl);
        writeJsPlusIconsSvg(htmlPath, serverUrl);
        writeTableJsPage(introspectedTable, htmlPath, modelUrl, fileServer, serverUrl, basePackage, aspectPackage);
        writeTableJsCustomTableJs(introspectedTable, htmlPath, modelUrl, fileServer, serverUrl, basePackage, aspectPackage);
        writeTableCssPage(introspectedTable, htmlPath, modelUrl, fileServer, serverUrl, basePackage, aspectPackage);
        writeTableCssCustomTableCss(introspectedTable, htmlPath, modelUrl, fileServer, serverUrl, basePackage, aspectPackage);
        writeBlankPage(htmlPath, modelUrl);
        writeTablePage(introspectedTable, htmlPath, modelUrl, fileServer, serverUrl, basePackage, aspectPackage);
    }

    public static void writeIndexPage(IntrospectedTable introspectedTable, String htmlPath, String modelUrl) {
        File file = null;
        OutputStream fileOutputStream = null;
        BufferedWriter bufferedWriter = null;
        try {
            File folder = new File(htmlPath + "");
            folder.mkdirs();
            file = new File(htmlPath + "/index.html");
            //如果文件不存在,则创建文件,如果已存在,则覆盖
            file.createNewFile();
            fileOutputStream = new FileOutputStream(file);
            bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream, "utf-8"));
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("后台管理\n");
            bufferedWriter.write("\n");
            writePageHead(bufferedWriter);
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("\n");
            bufferedWriter.write("
\n"); bufferedWriter.write("" + "登录\n" + "收起左边\n" + "\n" + "\n"); bufferedWriter.write("
\n"); bufferedWriter.write("\n"); bufferedWriter.write("
\n"); bufferedWriter.write("\n"); bufferedWriter.write("
\n"); bufferedWriter.write("\n"); bufferedWriter.write("\n"); System.out.println("write to file success : " + file.getPath()); } catch (IOException e) { e.printStackTrace(); } finally { MybatisUtilCommon.closeBufferWriterAndFileOutputStream(fileOutputStream, bufferedWriter); } } public static void writePageHead(BufferedWriter bufferedWriter) throws IOException { bufferedWriter.write("\n"); bufferedWriter.write("\n"); bufferedWriter.write("\n"); bufferedWriter.write("\n"); bufferedWriter.write("\n"); bufferedWriter.write("\n"); bufferedWriter.write("\n"); bufferedWriter.write("\n"); bufferedWriter.write("\n"); bufferedWriter.write("\n"); bufferedWriter.write("\n"); } public static void writeLeftFramePage(IntrospectedTable introspectedTable, String htmlPath, String modelUrl) { File file = null; OutputStream fileOutputStream = null; BufferedWriter bufferedWriter = null; String table = introspectedTable.getBaseRecordType(); String tableName = table.replaceAll(modelUrl + ".", ""); try { File folder = new File(htmlPath + ""); folder.mkdirs(); file = new File(htmlPath + "/page-left-frame.html"); //判断文件里有没有内容已经写过。 //如果文件不存在,则创建文件,如果已存在,则覆盖 List fileList = MybatisUtilCommon.getFileListFromConfigFile(); fileList.sort(new Comparator() { public int compare(Map o1, Map o2) { String tableIntrospectedTableName1 = (String) o1.get("tableIntrospectedTableName"); String tableIntrospectedTableName2 = (String) o2.get("tableIntrospectedTableName"); return tableIntrospectedTableName1.compareTo(tableIntrospectedTableName2); } }); file.createNewFile(); fileOutputStream = new FileOutputStream(file, false); bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream, "utf-8")); for (int i = 0; i < fileList.size(); i++) { Map fileMap = fileList.get(i); String tableIntrospectedTableName = (String) fileMap.get("tableIntrospectedTableName"); String tableDomainObjectName = (String) fileMap.get("tableDomainObjectName"); List fieldOriginalNames = (List) fileMap.get("fieldOriginalNames"); String tableRemarks = (String) fileMap.get("tableRemarks"); bufferedWriter.write("