• 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--
  • 相关阅读:
    行为型模式之 命令模式
    结构型模式之 代理模式
    oop编程思想
    2013应届毕业生各大IT公司待遇整理汇总篇(转)
    python定义class
    python——博客园首页信息提取与分析(转载有改动)
    深入浅出TCP/IP协议
    python基础之socket
    python基础
    c++stl之stack
  • 原文地址:https://www.cnblogs.com/simoncook/p/5163093.html
Copyright © 2020-2023  润新知