String capitalized = capitalizeFirstLetter("sign");
Method method = entity.getClass().getMethod("get" + capitalized, null);
Object invoke = method.invoke(entity, null);
if (invoke == null) {
throw new RuntimeException("invoke为空");
}
String sign = invoke.toString();
字符串首字母大写方法:
public static String capitalizeFirstLetter(String str) {
if (str == null || str.isEmpty()) {
return str;
}
char firstChar = str.charAt(0);
char capitalizedChar = Character.toUpperCase(firstChar);
String rest = str.length() > 1 ? str.substring(1) : "";
return capitalizedChar + rest;
}