0%

BeanUtils-copyProperties()复制Boolean类型失败

文章字数:83,阅读全文大约需要1分钟

使用copyProperties()复制时Boolean类型的一直无法复制,最后看到了一些信息

  1. 在网上找到分析源码513行只支持boolean
    1
    2
    3
    4
    5
    6
    7
    8
    9
    if (argCount == 0) {
    if (name.startsWith(GET_PREFIX)) {
    // Simple getter
    pd = new PropertyDescriptor(this.beanClass, name.substring(3), method, null);
    } else if (resultType == boolean.class && name.startsWith(IS_PREFIX)) {
    // Boolean getter
    pd = new PropertyDescriptor(this.beanClass, name.substring(2), method, null);
    }
    }
    Boolea类型的getXxx()可以使用,如果方法是isXxx()就只有boolean可以
    属性名不要用isXXX命名了