图一代码如下:
图二代码如下:
根据图1得到图2代码
package com.abc.esb.connect;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
/**
* @title: 自动生成get set <br/>
* @author: wangzs <br/>
* @date: 2017年9月10日
*/
public class AutoGetSetUtils {
public static void main(String[] args) {
String fileName = "E:/PsdTktExchange.java";// 文件名字
String beanName = "psdTktExchange";// java实例化bean名字
File file = new File(fileName);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
tempString = StringUtils.trim(tempString);
String[] words = tempString.split("\\s+");// [private, String, arrSchedule;]
// 过滤出来以private开始&&以;结束
if (tempString.startsWith("private") && tempString.endsWith(";")) {
StringBuffer newLine = new StringBuffer();// String arrSchedule = psdTktCoupon.getArrSchedule();
String attributesName = words[2].replace(";", "");
newLine.append(words[1] + " ");
newLine.append(attributesName);
newLine.append(" = ");
newLine.append(beanName + ".get");
newLine.append(attributesName.substring(0, 1).toUpperCase() + attributesName.substring(1));
newLine.append("();");
System.out.println(newLine);
}
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
}