0

使用 Castor 时如何将空字符串解组为 null?

4

1 回答 1

0
public class EmptyStringHandler extends GeneralizedFieldHandler {
    public Object convertUponGet(Object arg0) {
        //we don't know if it was really null or not, so just return it
        return arg0;
    }
    public Object convertUponSet(Object arg0) {
        if("".equals(arg0)) {
            return null;
        }
        return arg0;
    }
    public Class getFieldType() {
        return String.class;
    }
}


<field name="amid" type="integer" required="true" handler="cat.dds.fpsdma.fieldhandlers.EmptyIntegerHandler">
<bind-xml name="AMID" node="element" />
</field>
于 2011-08-25T18:51:52.160 回答