java代码生成器

  • c4_323843
    了解作者
  • 6.2MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-02 12:43
    上传日期
java代码自动生成!java代码生成器
my_code_generator.rar
内容介绍
package com.sendinfo; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.sendinfo.config.GenerateConfig; import com.sendinfo.db.DBOperator; import com.sendinfo.pojo.Table; import com.sendinfo.template.TemplateEngine; import com.sendinfo.util.DateUtil; public class Test { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { ApplicationContext ac = new ClassPathXmlApplicationContext("spring/spring-application.xml"); DBOperator dbOperator = (DBOperator) ac.getBean("dBOperator"); List<Table> list = dbOperator.getTables(); TemplateEngine templateEngine = (TemplateEngine) ac.getBean("templateEngine"); String dirurl = "d:\\pwb\\src\\main\\"; String module = GenerateConfig.MODULE; String author = GenerateConfig.AUTHOR; String now = DateUtil.format(new Date(), DateUtil.yyyy_MM_dd_HH_mm_ss); for (Table t : list) { Map<String, Object> map = new HashMap<String, Object>(); map.put("author", author); map.put("now", now); map.put("table", t); String str = null; File file = null; //生成mybatis PrintWriter pw = null; str = templateEngine.process("template/mybatis.ftl", map); file = new File(dirurl + "\\com\\sendinfo\\entity"); file.mkdirs(); file = new File(dirurl + "\\com\\sendinfo\\entity\\" + t.getJavaName() + ".xml"); pw = new PrintWriter(file); pw.print(str); pw.close(); //生成dao str = templateEngine.process("template/dao.ftl", map); file = new File(dirurl + "\\com\\sendinfo\\dao"); file.mkdirs(); file = new File(dirurl + "\\com\\sendinfo\\dao\\" + t.getJavaName() + "Dao.java"); pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template/daoImpl.ftl", map); file = new File(dirurl + "\\com\\sendinfo\\dao\\impl"); file.mkdirs(); file = new File(dirurl + "\\com\\sendinfo\\dao\\impl\\" + t.getJavaName() + "DaoImpl.java"); pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template/entity.ftl", map); file = new File(dirurl + "\\com\\sendinfo\\entity"); file.mkdirs(); file = new File(dirurl + "\\com\\sendinfo\\entity\\" + t.getJavaName() + ".java"); pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template/service.ftl", map); file = new File(dirurl + "\\com\\sendinfo\\service"); file.mkdirs(); file = new File(dirurl + "\\com\\sendinfo\\service\\" + t.getJavaName() + "Service.java"); pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template/serviceImpl.ftl", map); file = new File(dirurl + "\\com\\sendinfo\\service\\impl"); file.mkdirs(); file = new File(dirurl + "\\com\\sendinfo\\service\\impl\\" + t.getJavaName() + "ServiceImpl.java"); pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template/action.ftl", map); file = new File(dirurl + "\\com\\sendinfo\\action"); file.mkdirs(); file = new File(dirurl + "\\com\\sendinfo\\action\\" + t.getJavaName() + "Action.java"); pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template/edit.ftl", map); file = new File(dirurl + "\\webapp\\WEB-INF\\ftl\\" + module); file.mkdirs(); file = new File(dirurl + "\\webapp\\WEB-INF\\ftl\\" + module + "\\edit" + t.getJavaName() + ".ftl"); pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template/view.ftl", map); file = new File(dirurl + "\\webapp\\WEB-INF\\ftl\\" + module); file.mkdirs(); file = new File(dirurl + "\\webapp\\WEB-INF\\ftl\\" + module + "\\view" + t.getJavaName() + ".ftl"); pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template/list.ftl", map); file = new File(dirurl + "\\webapp\\WEB-INF\\ftl\\" + module); file.mkdirs(); file = new File(dirurl + "\\webapp\\WEB-INF\\ftl\\" + module + "\\list" + t.getJavaName() + ".ftl"); pw = new PrintWriter(file); pw.print(str); pw.close(); } File file = new File(dirurl + "\\spring\\"); if(!file.exists()){ file.mkdir(); } file = new File(dirurl + "\\struts\\"); if(!file.exists()){ file.mkdir(); } Map<String, Object> map = new HashMap<String, Object>(); map.put("tables", list); map.put("module", module); String str = templateEngine.process("template/struts.ftl", map); file = new File(dirurl + "\\struts\\struts-" + module + ".xml"); PrintWriter pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template/spring-dao.ftl", map); file = new File(dirurl + "\\spring\\spring-dao-" + module + ".xml"); pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template/spring-service.ftl", map); file = new File(dirurl + "\\spring\\spring-service-" + module + ".xml"); pw = new PrintWriter(file); pw.print(str); pw.close(); /*str = templateEngine.process("template/spring-mybatis.ftl", map); file = new File(dirurl + "\\spring-mybatis-" + module + ".xml"); pw = new PrintWriter(file); pw.print(str); pw.close();*/ str = templateEngine.process("template/properties_zh.ftl", map); file = new File(dirurl + "\\message_zh.properties"); pw = new PrintWriter(file); pw.print(str); pw.close(); str = templateEngine.process("template//properties1.ftl", map); file = new File(dirurl + "\\message.properties"); pw = new PrintWriter(file); pw.print(str); pw.close(); FileUtils.copyFile(new File("src/base/com/my/base/my.bat"), new File(dirurl+"/my.bat")); System.out.println("生成成功..."); } }
评论
    相关推荐
    • Java
      Java
    • java
      Java
    • Java
      Java
    • Java
      Java项目
    • Java
      Java 对于Java练习
    • java
      Java 此回购包括我学习Java的旅程。
    • java
      Java Java基础
    • Java
      Java
    • Java
      Java 我创建的Java项目
    • Java
      Java 2021/02/19 .java Main.java 学生.java Bmi.java 。班级 Bmi类 主类 MyBmi.class 学生班 学生样本类 2021/02/20 .java DeleteFile.java WriteFile.java MyDataPrint.java 。班级 DeleteFile.class ...