Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210219] iframe, 개발자 도구(F12), BeanUtils copyProperties #44

Open
JuHyun419 opened this issue Feb 19, 2021 · 0 comments
Open

Comments

@JuHyun419
Copy link
Owner

JuHyun419 commented Feb 19, 2021

iframe 부모 & 자식 접근

// 부모 함수 호출
parent.함수명;

// 부모 요소 접근
$(parent.document).find('셀렉터');

// 부모 오소 접근
parent.document.getElementById('아이디');

// 자식 요소 접근
$('#iframe 아이디').contents().find('셀렉터');

// 자식 요소 접근
frames['아이프레임아이디'].document.getElementById('아이디');

개발자 도구(F12)

  • 잘 활용하자 !!
  • console 창에서 바로 log 찍어서 해당 값 확인할 수 있음
  • 특정 요소에 접근할 때 ..

Spring BeanUtils copyProperties

  • 객체 복사할 때 setter 메소드로 일일이 설정하지 않아도 사용할 수 있음

  • 설정하지 않을 property가 있으면 매개변수에 넣어줄 수 있음(가변인자)

    // before
    person2.setName(person1.getName());
    person2.setAddress(person1.getAddress());
    person2.setId(person1.getId());
    person2.setPhone(person1.getPhone());
    
    // after
    BeanUtils.copyProperties(person1, person2);
    

    public static void copyProperties(Object source, Object target) throws BeansException {
        copyProperties(source, target, (Class)null, (String[])null);
    }

    public static void copyProperties(Object source, Object target, Class<?> editable) throws BeansException {
        copyProperties(source, target, editable, (String[])null);
    }

    public static void copyProperties(Object source, Object target, String... ignoreProperties) throws BeansException {
        copyProperties(source, target, (Class)null, ignoreProperties);
    }

    private static void copyProperties(Object source, Object target, @Nullable Class<?> editable, @Nullable String... ignoreProperties) throws BeansException {
        Assert.notNull(source, "Source must not be null");
        Assert.notNull(target, "Target must not be null");
        Class<?> actualEditable = target.getClass();
        if (editable != null) {
            if (!editable.isInstance(target)) {
                throw new IllegalArgumentException("Target class [" + target.getClass().getName() + "] not assignable to Editable class [" + editable.getName() + "]");
            }

            actualEditable = editable;
        }

        PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
        List<String> ignoreList = ignoreProperties != null ? Arrays.asList(ignoreProperties) : null;
        PropertyDescriptor[] var7 = targetPds;
        int var8 = targetPds.length;

        for(int var9 = 0; var9 < var8; ++var9) {
            PropertyDescriptor targetPd = var7[var9];
            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 var15) {
                            throw new FatalBeanException("Could not copy property '" + targetPd.getName() + "' from source to target", var15);
                        }
                    }
                }
            }
        }

    }
@JuHyun419 JuHyun419 changed the title [20210219] iframe, 개발자 도구(F12) [20210219] iframe, 개발자 도구(F12), BeanUtils copyProperties Feb 19, 2021
@JuHyun419 JuHyun419 added the Java label Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant