• BeanUtils设置字段值失败问题


    package org.apache.commons.beanutils;
    
    import static org.junit.Assert.*;
    
    import java.beans.BeanInfo;
    import java.beans.IntrospectionException;
    import java.beans.Introspector;
    import java.beans.PropertyDescriptor;
    import java.lang.reflect.InvocationTargetException;
    
    import org.junit.Test;
    
    /**
     * <一句话功能简述>
     * <功能详细描述>
     * 
     * @author  Chenxiaguang
     * @version  [版本号, 2016-1-27]
     * @see  [相关类/方法]
     * @since  [产品/模块版本]
     */
    public class BeanUtilsTest
    {
    
        /**
         * Test method for {@link org.apache.commons.beanutils.BeanUtils#setProperty(java.lang.Object, java.lang.String, java.lang.Object)}.
         */
        @Test
        public void testSetProperty()
        {
            TestBeanA testBeanA = new TestBeanA();
            try
            {
                BeanInfo beanInfo = null;
                try {
                    Class<?> beanClass = TestBeanA.class;
                    beanInfo = Introspector.getBeanInfo(beanClass);
                } catch (IntrospectionException e) {
                    return;
                }
                PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
                BeanUtils.setProperty(testBeanA, "Aac", "a");// fail
                BeanUtils.setProperty(testBeanA, "aac", "a");// ok
                BeanUtils.setProperty(testBeanA, "aBc", "b");// fail
                BeanUtils.setProperty(testBeanA, "ABc", "b");// ok
                BeanUtils.setProperty(testBeanA, "acc", "b");// ok
                BeanUtils.setProperty(testBeanA, "D", "b");// fail
                BeanUtils.setProperty(testBeanA, "d", "b");// ok
            }
            catch (IllegalAccessException e)
            {
                e.printStackTrace();
            }
            catch (InvocationTargetException e)
            {
                e.printStackTrace();
            }
        }
    
    }

    用于测试的bean

    package org.apache.commons.beanutils;
    
    /**
     * <一句话功能简述>
     * <功能详细描述>
     * 
     * @author  Chenxiaguang
     * @version  [版本号, 2016-1-27]
     * @see  [相关类/方法]
     * @since  [产品/模块版本]
     */
    public class TestBeanA
    {
    
        private String Aac;
        
        private String ABc;
        
        private String acc;
        
        private String D;
    
        public String getAac()
        {
            return Aac;
        }
    
        public void setAac(String aac)
        {
            Aac = aac;
        }
    
        public String getABc()
        {
            return ABc;
        }
    
        public void setABc(String aBc)
        {
            ABc = aBc;
        }
    
        public String getAcc()
        {
            return acc;
        }
    
        public void setAcc(String acc)
        {
            this.acc = acc;
        }
    
        public String getD()
        {
            return D;
        }
    
        public void setD(String d)
        {
            D = d;
        }
        
        
    }
    --EOF--
  • 相关阅读:
    Spring Boot----处理异常
    Spring Boot----SpringBoot中SpringMVC配置原理
    git----常见问题
    源码分析----Mybatis
    spring----一些xml配置
    Spring MVC----spring MVC 异常处理
    java----小游戏
    java----垃圾回收机制
    java----常见jar包
    anconda安装
  • 原文地址:https://www.cnblogs.com/simoncook/p/5163093.html
Copyright © 2020-2023  润新知