编写自动代码模板

来自ling
跳转至: 导航搜索

注意事项

  1. 类字段不支持boolean,int,long等非类类型字段 已支持

添加方法

AutoProjectUtils中添加一个方法,比如

	/**
	 * iris define
	 * @param resultfolder
	 * @param class1
	 */
	public static void executeIrisDefine(String resultfolder,OneToManyPojo oneToManyPojo)
	{
		List<OneToManyExporter> exporters=new ArrayList<OneToManyExporter>();
		exporters.add(new OneToManyExporter(resultfolder, oneToManyPojo, "irisdefine/dao/Dao.ftl", "cache/IrIs"+oneToManyPojo.getOne().getShortName()+"Dao.java"));
		exporters.add(new OneToManyExporter(resultfolder, oneToManyPojo, "irisdefine/dao/impl/DaoImpl.ftl", "cache/IrIs"+oneToManyPojo.getOne().getShortName()+"DaoImpl.java"));
		exporters.add(new OneToManyExporter(resultfolder, oneToManyPojo, "irisdefine/model/Node.ftl", "cache/IrIs"+oneToManyPojo.getOne().getShortName()+"Node.java"));
		exporters.add(new OneToManyExporter(resultfolder, oneToManyPojo, "irisdefine/service/Service.ftl", "service/"+oneToManyPojo.getOne().getShortName()+"Service.java"));
		exporters.add(new OneToManyExporter(resultfolder, oneToManyPojo, "irisdefine/service/impl/ServiceImpl.ftl", "service/impl/"+oneToManyPojo.getOne().getShortName()+"ServiceImpl.java"));
		exporters.add(new OneToManyExporter(resultfolder, oneToManyPojo, "irisdefine/view/java.ftl", "view/"+oneToManyPojo.getOne().getShortName()+"Manager.java"));
		exporters.add(new OneToManyExporter(resultfolder, oneToManyPojo, "irisdefine/view/js.ftl", "view/"+oneToManyPojo.getOne().getShortName()+"Manager.js"));
		exporters.add(new OneToManyExporter(resultfolder, oneToManyPojo, "irisdefine/view/view.ftl", "view/"+oneToManyPojo.getOne().getShortName()+"Manager.view.xml"));
		exporters.add(new OneToManyExporter(resultfolder, oneToManyPojo, "irisdefine/view/i18n.ftl", "view/"+oneToManyPojo.getOne().getShortName()+"Manager.properties"));
		exporters.add(new OneToManyExporter(resultfolder, oneToManyPojo, "irisdefine/view/i18n.zh_CN.ftl", "view/"+oneToManyPojo.getOne().getShortName()+"Manager.zh_CN.properties"));
		for(OneToManyExporter exporter:exporters)
		{
			exporter.execute();
		}
	}

创建模板文件

  • 讲需要复制的文件按需要的目录组织形式放置

如:

irisdefine
model
dao
impl
service
Service.ftl
impl
ServiceImpl.ftl
view
  • 将上面copy的文件修改为.ftl结尾
  • 修改第一步方法中需要使用的模板和需要输出的文件

修改模板文件