BeanUtils.copyProperties 需要getset方法支持
生活随笔
收集整理的這篇文章主要介紹了
BeanUtils.copyProperties 需要getset方法支持
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
今天在調用這個方法時,發現屬性沒有映射上,結果一看是model類沒有加上getset方法 `PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable); List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null);
for (PropertyDescriptor targetPd : targetPds) {Method writeMethod = targetPd.getWriteMethod();if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) {PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());if (sourcePd != null) {Method readMethod = sourcePd.getReadMethod();if (readMethod != null &&ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType())) {try {if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {readMethod.setAccessible(true);}Object value = readMethod.invoke(source);if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {writeMethod.setAccessible(true);}writeMethod.invoke(target, value);}catch (Throwable ex) {throw new FatalBeanException("Could not copy property '" + targetPd.getName() + "' from source to target", ex);}}}}}`轉載于:https://my.oschina.net/penghaozhong/blog/1944084
總結
以上是生活随笔為你收集整理的BeanUtils.copyProperties 需要getset方法支持的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MikroTik RouterOS获取在
- 下一篇: Docker图形化管理工具之Portai