/**
获取一个对象里的全部属性
List<String> pInfoFields = Arrays.stream(pInfo.getClass().getDeclaredFields()).map(Field::getName).collect(Collectors.toList());
*/

/*
* * 获取属性值 * @param obj * @param property * @return */ public static Object getObjProVal(Object obj, String property) { Object val = null; int len = property.length(); String methodName = "get" + property.substring(0, 1).toUpperCase() + property.substring(1, len); try { Method method = obj.getClass().getMethod(methodName); val = method.invoke(obj); } catch (Exception e) { } return val; } /** * 设置属性值 * @param obj * @param property * @param value * @return */ public static void setObjProVal(Object obj, String property, Object value) { int len = property.length(); String methodName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1, len); try { Method method = obj.getClass().getMethod(methodName, value.getClass()); method.invoke(obj, value); } catch (Exception e) { e.printStackTrace(); } }

 

相关文章:

  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-27
  • 2022-01-17
  • 2022-12-23
  • 2021-08-21
  • 2022-02-11
  • 2022-02-11
  • 2022-12-23
相关资源
相似解决方案