}
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.Converter;
public class Test {
public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {
Bean1 bean1 = new Bean1();
bean1.setA("22");
bean1.setB("fff");
bean1.setTime("2017-01-22 11:11:11");
Bean2 bean2 = new Bean2();
resp();
BeanUtils.copyProperties(bean2, bean1);
System.out.println(bean2.getA());
System.out.println(bean2.getB());
System.out.println(bean2.getTime());
}
private static void resp() {
ConvertUtils.register(new Converter() {
@Override
public Object convert(Class arg0, Object value) {
if(value != null &&!"".equals(value.toString())){
String v=value.toString();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:MM:ss");
try {
return sdf.parse(v);
} catch (ParseException e) {
e.printStackTrace();
}
}
return null;
}
}, Date.class);
}
}