public class CarConfigUtil {
public static void changeValue(Object obj, Class clazz) {
Class[] test = { String.class };
String temp = "";
try {
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (method.getName().indexOf("get") == 0 && !method.getName().equals("getClass")&&method.getReturnType().equals(String.class)) {
String str = (String) (method.invoke(obj, null));
if (str != null) {
if (str.equals("1")) {
temp = "●";
clazz.getMethod("s" + method.getName().substring(1), test).invoke(obj, temp);
} else if (str.equals("2")) {
temp = "○";
clazz.getMethod("s" + method.getName().substring(1), test).invoke(obj, temp);
} else if (str.equals("3")) {
temp = "×";
clazz.getMethod("s" + method.getName().substring(1), test).invoke(obj, temp);
}
}else{
clazz.getMethod("s" + method.getName().substring(1), test).invoke(obj, "");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
直接上代码,原理可以去百度参考。
changeValue的param的第一参数为实体类,第二个为该的.class
public static void changeValue(Object obj, Class clazz) {
Class[] test = { String.class };
String temp = "";
try {
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (method.getName().indexOf("get") == 0 && !method.getName().equals("getClass")&&method.getReturnType().equals(String.class)) {
String str = (String) (method.invoke(obj, null));
if (str != null) {
if (str.equals("1")) {
temp = "●";
clazz.getMethod("s" + method.getName().substring(1), test).invoke(obj, temp);
} else if (str.equals("2")) {
temp = "○";
clazz.getMethod("s" + method.getName().substring(1), test).invoke(obj, temp);
} else if (str.equals("3")) {
temp = "×";
clazz.getMethod("s" + method.getName().substring(1), test).invoke(obj, temp);
}
}else{
clazz.getMethod("s" + method.getName().substring(1), test).invoke(obj, "");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
直接上代码,原理可以去百度参考。
changeValue的param的第一参数为实体类,第二个为该的.class