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

com.github.wtbian.core.ProcessImpl Maven / Gradle / Ivy

Go to download

The mvc-generator makes it easier to write code with spring-mvc applications. mvc-generator generate code with freemarker template of controller, service and dao etc level object using maven plugin. Simplicity is the biggest advantage of the generator code over generating code tools.

There is a newer version: 1.0.4.1
Show newest version
package com.github.wtbian.core;

import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.*;
import java.util.Map;
import java.util.function.Consumer;

/**
 * Created by bianwentao on 2019/1/27.
 */
public class ProcessImpl implements Consumer{

    Template template;

    private EntityToModuleHelper couponDataMapToPojoHelper=new EntityToModuleHelper();

    public ProcessImpl(Template template) {
        this.template = template;
    }

    @Override
    public void accept(Entity entity) {
        try {
            Module module = couponDataMapToPojoHelper.apply(entity);
            Map root = module.getRoot();
            File javaFile = module.getJavaFile();

            // 步骤四:合并 模板 和 数据模型
            // 创建.java类文件
            if (javaFile != null) {
                Writer javaWriter = new FileWriter(javaFile);
                template.process(root, javaWriter);
                javaWriter.flush();
                System.out.println("文件生成路径:" + javaFile.getCanonicalPath());
                javaWriter.close();
            }
            // 输出到Console控制台
            Writer out = new OutputStreamWriter(System.out);
            template.process(root, out);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy