当前位置: 首页 > 工具软件 > BeanGenerator > 使用案例 >

BeanGenerator_5

袁泰平
2023-12-01
	/**
	 * Step 3:根据“内容”和“输出路径”导出文件
	 * @param content 内容
	 * @param outputPath 输出路径
	 */
	private void output(String content, String outputBasePath) {
		PrintWriter printWriter = null;
		try {
			printWriter = new PrintWriter(new BufferedWriter(new FileWriter(
					outputBasePath)));
			printWriter.println(content);
			printWriter.flush();
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			printWriter.close();
		}
	}

	public void generate() {
		String templatePath = "";
		String result = "";
		String fileName = "";
		importBeans();
		for (int i = 0; i < templatePaths.length; i++) {
			templatePath = templatePaths[i];
			if (Util.isNull(templatePath))
				continue;
			for (Bean bean : beans) {
				result = importTemplate(templatePath, bean);
				if (templatePath.indexOf(".java") > 0)
					fileName = bean.getName()
							+ templatePath.substring(templatePath
									.lastIndexOf("."));
				else
					fileName = Util.one2LowerCase(bean.getName())
							+ templatePath.substring(templatePath
									.lastIndexOf("."));
				output(result, outputBasePath + fileName);
			}
		}
	}
}

 bean.java

for (Parameter parameter : parameters) {
			this.setA(this.getA()+"this."+parameter.getName()+"="+parameter.getName()+";\n");
			this.setB(this.getB()+parameter.getClazz()+" "+parameter.getName()+",");
			this.setC(this.getC()+"+\""+parameter.getName()+": \"+this."+parameter.getName()+"\n");
			this.setD(this.getD()+"@param "+parameter.getName()+": "+parameter.getClazz()+" "+parameter.getNote()+"\n * ");
		}
		
		this.setA(this.getA().substring(0,this.getA().length()-1));
		this.setB(this.getB().substring(0,this.getB().length()-1));
		this.setC(this.getC().substring(0,this.getC().length()-1));
		this.setC("\"{\""+this.getC()+"+\"}\"");
		this.setD(this.getD().substring(0,this.getD().length()-4));

 

 类似资料:

相关阅读

相关文章

相关问答