난 그냥 BeanUtils 라이브러리를 사용해야한다고 생각해. 내 견본을보고, CustomerBean에서 SellerBean으로 복사 속성을 수행합니다.
package testes.beanutils;
import org.apache.commons.beanutils.BeanUtils;
public class Main {
public static void main(String[] args) throws Exception {
Customer customer = new Customer();
customer.setId((long)1);
customer.setName("Bruno");
customer.setLastname("Tafarelo");
Seller seller = new Seller();
BeanUtils.copyProperties(seller, customer);
System.out.println(customer);
System.out.println(seller);
}
}
class Customer {
private Long id;
private String name;
private String lastname;
//getters and setters
//toString
}
class Seller {
private Long id;
private String name;
private int sales;
//getters and setters
//toString
}
감사하지만 왜? 내가 왜 하나를 사용해야하지만 다른 하나는 사용하지 말아야하는지에 대한 해답을 찾고 있습니다. 그들은 둘 다 당신의 모범을 수행 할 수있는 것처럼 보입니다. – GokcenG
음. 스프링 반사에 대해 설명 할 수는 없지만 springcore가 이미 내 앱의 종속성 인 경우이 API를 수행합니다. BeanUtils는 작고 단순하며 예를 들어 스트럿과 같은 많은 프로젝트에서 사용되었습니다. BeanUtils는 캐시를 사용하여 반사 사용을 빠르게 할 수 있습니다. 보안, 나는 다른 유형의 가치를 가진 부동산을 암묵적으로 설정할 수 없다는 것을 알고 있습니다. BeanUtils를 사용하여 bean에 양식 html (요청 매개 변수)을 구문 분석합니다. 복잡한 Collection을 채울 수는 없지만 간단한 목록과 중첩 된 속성은 잘 작동합니다. 죄송합니다 더 이야기하거나이 라이브러리를 비교할 수 없습니다. – btafarelo