【jfinal】【01】根据模板生成类

1.引入pom


		    com.jfinal
		    jfinal
		    4.9.01
		

2.写模板文件

RabbitmqSimpleJob.html

package com.zhenzhen.common.redisv2.consumer.elasticjob;

public class RabbitmqSimpleJob#(num) extends RabbitmqSimpleJob {
}

3.java代码生成模板

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import com.jfinal.kit.Kv;
import com.jfinal.template.Engine;

public class TestjfinalRabbitmqSimpleJob {
    
    public static void main(String[] args) throws IOException {
        
        for(int i=0;i<=127;i++) {
            BufferedWriter output = null;
            try {
                File file = new File("D:\\jfinal\\RabbitmqSimpleJob"+i+".java");
                File path = new File(file.getParent());
                if ( ! path.exists() ) {
                    path.mkdirs();
                }
                output = new BufferedWriter(new FileWriter(file));
                
                Kv kv = new Kv();
                kv.set("num",i);
                
                Engine.use().getTemplate("D:\\jfinal\\Template\\RabbitmqSimpleJob.html").render(kv,output);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally {
                if(output!=null) {
                    output.close();
                }
                
            }
        }
        
    }

}

你可能感兴趣的:(java)