private LocalDateTime PP_SENT_DATE;
需要写成:
private LocalDateTime ppSentDate;
public Integer getDetainPermitDays() {
return detainPermitDays;
}
需要写成:(先处理完字段,再生成set、get方法)
@Column(name="detain_permit_days")
public Integer getDetainPermitDays() {
return detainPermitDays;
}
这个类大概有100多个这样的字段,所以写了一个方法:
// 写完后,想起电视剧白眉大侠的片头曲:传说中,他有着绝对精彩和浪漫的身手
public static void test() throws Exception {
//读取文件(字符流)
BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream("C:\\Users\\tom\\Desktop\\TblCaseCommonBasic.java"),"utf-8"));// 这里主要是涉及中文
//BufferedReader in = new BufferedReader(new FileReader("d:\\1.txt")));
//写入相应的文件
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("C:\\Users\\tom\\Desktop\\2.txt"),"utf-8"));
//BufferedWriter out = new BufferedWriter(new FileWriter("d:\\2.txt"));
//读取数据
//循环取出数据
String str = null;
while ((str = in.readLine()) != null) {
System.out.println(str);
// 处理每一行
str = line(str);
if(str.contains("\n")) {
String[] split = str.split("\n");
out.write(split[0]);
out.newLine();
out.write(split[1]);
out.newLine();
}else {
out.write(str);
out.newLine();
}
//写入相关文件
// out.write(str);
// out.newLine();
}
//清楚缓存
out.flush();
//关闭流
in.close();
out.close();
}
public static String line(String a) {
// String a = "private LocalDateTime PP_SENT_DATE;// DATE 行政处罚缴款书送达日期";
// String a = "public Integer getDetainPermitDays() {";
if(a.contains(";") && a.contains("private")) {
String[] split = a.split(";");
// 找到想要处理的字符串
String a1 = split[0]; // private LocalDateTime PP_SENT_DATE
int lastIndexOf = a1.lastIndexOf(" ");
// System.out.println("lastIndexOf:"+lastIndexOf);
String substring = a1.substring(lastIndexOf+1);
// System.out.println("substring:"+substring);
// 已经找到,要处理该字符串,处理substring PP_SENT_DATE
substring = substring.toLowerCase();// pp_sent_date
if(substring.contains("_")) {
String[] split2 = substring.split("_");
StringBuilder sb = new StringBuilder();
for(int i=0;i<split2.length;i++) {
if(i==0) {
sb.append(split2[i]);
}else {
char charAt = split2[i].charAt(0);
String upperCase = String.valueOf(
split2[i].charAt(0)).toUpperCase();
sb.append(upperCase); // 去掉下划线,后面的字符大写
String substring2 = split2[i].substring(1);
sb.append(substring2);// 不要忘了后面的字符
}
}
substring=sb.toString();
}
// 处理完之后,整理出结果
StringBuilder sb = new StringBuilder();
sb.append(a1.substring(0, lastIndexOf)).append(" ").append(substring).append(";");
if(split.length > 1) { // 有这样的行,分号后面没有内容:private String name;
sb.append(split[1]);
}
// System.out.println("最终结果:");
System.out.println(sb.toString());
return sb.toString();
/*
* public String getCompanyName() {
return companyName;
}
public Integer getDetainPermitDays() {
return detainPermitDays;
}
*/
}else if(a.contains("get") && a.contains("public")){
// public Integer getDetainPermitDays() {
StringBuilder asb = new StringBuilder();
int i1 = a.indexOf("get");
int i2 = a.indexOf("()");
String substring = a.substring(i1+3, i2); // DetainPermitDays
// System.out.println(substring);
char[] charArray = substring.toCharArray();
int sum = 0;
for(int i=0;i<charArray.length;i++) {
if(charArray[i]>='A' && charArray[i]<='Z') {
sum++;
}
}
// System.out.println("sum:"+sum);
StringBuilder sb = new StringBuilder();
if(sum >= 2) {
String s = String.valueOf(charArray[0]).toLowerCase();
sb.append(s);
// 有两个大写字母,需要加下划线
for(int i=0;i<charArray.length;i++) {
if(charArray[i]>='A' && charArray[i]<='Z' && i > 0) {
// 大写转为小写,并且前面加下划线
String lowerCase = String.valueOf(charArray[i]).toLowerCase();
sb.append("_").append(lowerCase);
}else {
if(i > 0) {
sb.append(charArray[i]);
}
}
}
}
// 返回结果 @Column(name="citizen_sex")
if(sb.toString().length() > 0) { // 一个单词的不需要加
asb.append(" @Column(name=\""+sb+"\")").append("\n");
}
StringBuilder ss = asb.append(a);
String lowerCase = ss.toString();
// System.out.println(lowerCase);
return lowerCase;
}else {
return a;
}
}
···
网友评论