-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathParseDB2Property.java
61 lines (58 loc) · 1.49 KB
/
ParseDB2Property.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @author: guangxush
* @create: 2020/10/03
*/
public class ParseDB2Property {
/**
* 输入:userId,用户ID
*
* 输出:
*
* /**
* * 用户ID
* \*\/
* private String userId
* @param args
*/
public static void main(String[] args) {
System.out.println(parse("userId,用户ID"));
}
/**
* 解析数据库字段
* @param inputDbColumn 输入格式为 userId,用户ID
* @return
*/
private static String parse(String inputDbColumn){
String[] array = inputDbColumn.split(",");
return parseNote(array[1]) + "\n" + parseProperty(array[0]);
}
/**
* 生成注释
* @param comment
* @return
*/
private static String parseNote(String comment){
return String.format("/**\n" +
" * %s\n" +
" */", comment);
}
/**
* 生成变量,只针对varchar --> String
* @param value
* @return
*/
private static String parseProperty(String value){
char[] array = value.toCharArray();
StringBuffer buffer = new StringBuffer();
for(int i=0;i<array.length;i++){
if(array[i]=='_'){
// 下一位转换成大写字母
array[i+1] -= 32;
continue;
}
buffer.append(array[i]);
}
String property = String.format("private String %s;", buffer.toString());
return property;
}
}