public class Test {
/**
* @param args
*/
public static void main(String[] args) {
String[] attr =
new String[] {"Student_ID", "Study_NO"};
String[] annotation =
new String[] {"先生ID", "勉強番号"};
for (int i = 0; i < attr.length; i++) {
String strAttr = attr[i].toLowerCase();
String strAnn = annotation[i];
while (strAttr.indexOf('_') != -1) {
int index = strAttr.indexOf('_');
strAttr = strAttr.replaceFirst("_", "");
String first = strAttr.substring(0, index);
String bigChar =
String.valueOf(strAttr.charAt(index)).toUpperCase();
String end = strAttr.substring(index + 1);
strAttr = first
+ bigChar
+ end;
}
StringBuffer sb = new StringBuffer();
sb.append(" /**\n");
sb.append(" * "
+ strAnn
+ "\n");
sb.append(" */\n");
sb.append(" private String "
+ strAttr
+ ";\n");
System.out.println(sb);
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
String[] attr =
new String[] {"Student_ID", "Study_NO"};
String[] annotation =
new String[] {"先生ID", "勉強番号"};
for (int i = 0; i < attr.length; i++) {
String strAttr = attr[i].toLowerCase();
String strAnn = annotation[i];
while (strAttr.indexOf('_') != -1) {
int index = strAttr.indexOf('_');
strAttr = strAttr.replaceFirst("_", "");
String first = strAttr.substring(0, index);
String bigChar =
String.valueOf(strAttr.charAt(index)).toUpperCase();
String end = strAttr.substring(index + 1);
strAttr = first
+ bigChar
+ end;
}
StringBuffer sb = new StringBuffer();
sb.append(" /**\n");
sb.append(" * "
+ strAnn
+ "\n");
sb.append(" */\n");
sb.append(" private String "
+ strAttr
+ ";\n");
System.out.println(sb);
}
}
}
Java生成Table Model属性注释
这段代码展示了如何使用Java创建一个Table Model的属性注释。通过对输入的属性名进行处理,将下划线转为驼峰式命名,并生成对应的Java注释。这有助于在数据表模型中为字段提供清晰的描述。
249

被折叠的 条评论
为什么被折叠?



