com.eshore.tools.Alias Maven / Gradle / Ivy
package com.eshore.tools;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
public class Alias {
public static void main(String[] args) {
System.out.println(db2pro("mq__admin__detail"));
System.out.println(pro2db("mqABGFGdminDetail"));
}
static Map alias= new HashMap();
public static Map getAlias(Class clazz) {
Map map = alias.get(clazz);
if(map!=null)return map;
map= new HashMap();
alias.put(clazz,map);
Method[] method = clazz.getMethods();
/**
* 给实例填充
*/
for (int i = 0; i < method.length; i++) {
Method meth = method[i];
String name =meth.getName();
/**
* 当不是set的
*/
if (!name.startsWith("set"))
continue;
name=name.substring(3);
String db=pro2db(name);
String pro=firstLower(name);
if(!db.equals(pro))
map.put(pro,db);
}
return map;
}
public static String db2pro(String str) {
char[] cs= str.toCharArray();
boolean up=false;
int index=0;
for(int i=0;i64&&c<91;
}
public static char toUpper(char c) {
if(c>96&&c<123)return (char)(c-32);
return c;
}
public static char toLower(char c) {
if(c>64&&c<91)return (char)(c+32);
return c;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy