zoukankan      html  css  js  c++  java
  • 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--
  • 相关阅读:
    枚举和字符串之间的转换 [转帖]
    escape,encodeURI,encodeURIComponent函数比较[转帖]
    .net中的Provider模式 [转帖]
    ogg转到mp3
    四季养生(樊正伦教授)
    JavaScript高阶之路
    Python初识
    理解error和exception之间的区别(转)
    一些有用的话
    《爱在雨季》片尾曲
  • 原文地址:https://www.cnblogs.com/simoncook/p/5163093.html
Copyright © 2011-2022 走看看