BeanUtils.copyProperties时间处理

对象copy的时候时间支持
重写父类方法:
public static void copyBean(Object target, Object form) {
        ConvertUtils.register(new Converter() {
            public Object convert(Class cls, Object obj) {
                if (obj instanceof Date) {
                    return obj;
                    // return new Date(((Timestamp)obj).getTime());
                }
                String p = (String)obj;
                if (p == null || p.trim().length() == 0) {
                    return null;
                }
                return obj;

            }
        }, Date.class);
        try {
            BeanUtils.copyProperties(target, form);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
   

猜你喜欢

转载自xianlincai.iteye.com/blog/2338788