解析XML文档过程中对于未知类型的值的处理

来源:互联网 发布:平均利润知乎 编辑:程序博客网 时间:2024/05/22 06:46
在定义XML需要对系统数据初始化时,如果取到的节点是数值类型可以通过
Attribute attribute = (Attribute) a.next();Class fc = PropertyUtils.getPropertyType(obj, attribute.getName());//得到改属性的真实类型System.out.println(fc);BeanUtils.setProperty(obj, attribute.getName(), fc.getConstructor(String.class).newInstance(attribute.getData()));//调用如new Integer("1")的方法进行赋值

0 0